Technology Tales

Notes drawn from experiences in consumer and enterprise technology

10:13, 12th January 2023

Open Graph protocol

The Open Graph protocol allows web pages to function as rich objects within social networks by using metadata tags in the HTML head, specifying properties such as title, type, image and canonical URL. These tags enable consistent representation across platforms, with optional elements for additional details like descriptions, locales and media. Structured properties provide extended information for images, videos and audio, while predefined object types serve categories like music, video, articles and books, each with specific attributes. The protocol draws on existing standards and is supported by various tools and libraries, facilitating integration and enhancing how content is shared and displayed online.

18:06, 10th January 2023

What is Open Graph, and how can I use it for my website?

Open Graph is a protocol developed to standardise metadata on web pages, enabling content to be represented consistently when shared on social media platforms. It uses tags such as og:title, og:type, og:image and og:url to define a page's title, content type, visual representation and URL, ensuring that links shared online display relevant information in previews. Additional tags like og:description and og:locale can further enhance clarity and localisation.

While social networks may generate default previews without Open Graph, these often lack visual appeal or context, reducing engagement. Proper implementation involves specifying high-resolution images, adhering to platform-specific image requirements and testing tags using tools provided by platforms like Facebook. Effective use of Open Graph improves visibility and encourages users to interact with content by presenting it more attractively within crowded social feeds.

16:49, 17th December 2022

Lambda Functions in Python

Lambda Calculus

Lambda calculus is a formal system in mathematical logic, developed by Alonzo Church in the 1930s as part of his research into the foundations of mathematics, that expresses computation through function abstraction and application using variable binding and substitution. It consists of lambda terms built from variables, abstractions and applications, with transformation rules including alpha-conversion, beta-reduction and eta-conversion allowing terms to be reduced to equivalent forms. The system is Turing complete, meaning it can simulate any Turing machine, and underpins much of modern computer science, particularly functional programming languages such as ML and Haskell.

In Python, lambda functions draw directly from this formalism, providing anonymous, single-expression functions that are well suited for use as inline parameters in higher-order functions such as map(), filter() and sorted(). While lambda functions can technically be assigned to variables, this practice is discouraged in favour of named function definitions, which offer better readability and clearer error tracing. The broader lambda calculus framework encompasses typed variants, recursion via fixed-point combinators such as the Y Combinator, Church encodings for arithmetic and Boolean logic, and various reduction strategies including normal order, applicative order and call-by-value, each with different implications for termination and efficiency. Its influence extends beyond computer science into mathematics, linguistics, philosophy and category theory.

13:18, 30th November 2022

One deadly sin SAS programmers should stop committing

A common but serious mistake made by SAS programmers is embedding unmasked passwords directly into their code, which exposes sensitive data to anyone who gains access to the file. Storing passwords in macro variables offers no real protection either, as simple commands can reveal their values in the SAS log.

The recommended minimum safeguard is to use PROC PWENCODE, a built-in SAS procedure that encodes passwords so they cannot be read at a glance, with the SAS system handling decoding automatically during compilation. Three encoding methods are available, ranging from a basic 32-bit key approach to stronger 256-bit key options with added salt.

Encoded passwords still need to be stored in files protected by file system permissions or other access controls, since a determined attacker can still decode them. For more comprehensive protection, particularly in Business Intelligence environments, additional strategies such as authentication domains, token-based authentication and integrated Windows authentication can eliminate the need to reference passwords in code altogether. The key distinction to understand is that encoding translates characters through a lookup table, whereas encryption uses mathematical operations and a key, making it considerably harder to crack.

11:38, 21st November 2022

Python Global Keyword

In Python, the global keyword is used to modify a variable that exists outside the current function scope. By default, variables created inside a function are local to that function, while variables defined outside are global without needing any special declaration.

Attempting to modify a global variable from within a function without using the global keyword will result in an UnboundLocalError, as Python treats the variable as a local reference that has not yet been assigned. By declaring a variable as global inside a function, the programmer signals that any modifications made to it should apply to the global instance rather than creating a new local one. Using the global keyword outside a function has no practical effect, and it is only meaningful when there is an intention to write to a global variable from within a local context.

22:34, 18th November 2022

7 Tips To Produce Readable Data Science Code

Writing readable code is a critical skill in data science, where clarity becomes even more important as complexity increases. Effective practices include planning a clear structure before coding, using descriptive variable names to aid future understanding, organising code into well-defined functions that encapsulate specific tasks and including concise docstrings to explain purpose and functionality. Leveraging existing libraries rather than reinventing solutions can save time and reduce errors, while prioritising simplicity in code steps over overly compacted logic helps maintain flexibility. Consistency in naming conventions, formatting and modular organisation further enhances readability, making code easier to maintain and collaborate on. These strategies not only improve individual productivity but also ensure that code remains accessible to others, supporting long-term project sustainability and reducing the cognitive load for future users.

17:00, 27th October 2022

CALL EXECUTE made easy for SAS data-driven programming

The CALL EXECUTE routine in SAS is a powerful tool for building data-driven programmes, operating by accepting a character string or expression as its argument and dynamically generating SAS code during data step iterations, with that code then executing after the DATA step completes. Its behaviour varies depending on how its argument is constructed: macro variable references in double quotes are resolved during compilation by the macro pre-processor, whilst those in single quotes are resolved by CALL EXECUTE itself during execution.

A notable pitfall arises when a macro contains non-macro language constructs that assign macro variables at run time, such as CALL SYMPUT or an INTO clause, as CALL EXECUTE may attempt to resolve those references too early, before the relevant code has executed, resulting in unresolved macro variables. The recommended solution is to use the %nrstr macro function to mask the percent and ampersand characters, effectively preventing premature macro resolution and deferring execution until after the DATA step boundary.

The argument to CALL EXECUTE can also be a SAS character variable rather than a literal string, in which case the same rules apply regarding macro reference resolution. When used with a driver table, CALL EXECUTE can control not only the parameter values passed to a macro but also which macro is invoked on each iteration, making it a flexible mechanism for fully automated, data-driven SAS programme development.

09:40, 24th October 2022

SAS NWKDOM Function

The NWKDOM function in SAS calculates the date of the nth occurrence of a specified weekday within a given month and year, returning a numeric SAS date value. It accepts parameters for the week number (1–5), weekday (1–7, with Sunday as 1), month (1–12) and a four-digit year and is particularly useful for determining dates of events not covered by standard holiday functions. For example, it can identify the third Monday in May 2012 or the last Monday in May 2012, with outputs formatted using SAS date conventions.

09:39, 24th October 2022

The JSON LIBNAME Engine: Real-World Applications Using Open APIs

The JSON LIBNAME engine in SAS offers a straightforward way to access and extract data from JSON files, eliminating the need for complex parsing code. This feature is particularly useful when dealing with APIs that return data in JSON format, such as those from Google Maps or the US Census Bureau. By using the engine, users can directly import structured data into SAS without manually interpreting the JSON structure.

For instance, reverse geocoding coordinates through the Google Maps API becomes a simple process, with the engine automatically generating datasets containing relevant information like addresses and geographical details. Similarly, the US Census API allows users to explore datasets by first reading descriptor files, which list available data sources.

A macro can then dynamically fetch and process example JSON files from these sources, streamlining the workflow significantly. This capability not only saves time but also ensures that new data added to APIs is easily integrated into SAS analyses.

The engine's reliability and ease of use make it a valuable tool for SAS programmers, enabling them to leverage a wide range of JSON-based data sources efficiently. As more services adopt JSON for data exchange, the JSON LIBNAME engine positions SAS users to adapt quickly and effectively to new opportunities.

20:49, 23rd October 2022

WorldTimeAPI is a straightforward web service that returns the current local time for a given timezone in either plain or JSON format. Alongside the current date/time, the service provides additional details such as the UTC offset, day of the week, day of the year, week number, Unix timestamp and daylight saving time information, including whether DST is currently active and the dates on which it begins and ends. The service does not use cookies and is free to query via a simple API call.

  • The content, images, and materials on this website are protected by copyright law and may not be reproduced, distributed, transmitted, displayed, or published in any form without the prior written permission of the copyright holder. All trademarks, logos, and brand names mentioned on this website are the property of their respective owners. Unauthorised use or duplication of these materials may violate copyright, trademark and other applicable laws, and could result in criminal or civil penalties.

  • All comments on this website are moderated and should contribute meaningfully to the discussion. We welcome diverse viewpoints expressed respectfully, but reserve the right to remove any comments containing hate speech, profanity, personal attacks, spam, promotional content or other inappropriate material without notice. Please note that comment moderation may take up to 24 hours, and that repeatedly violating these guidelines may result in being banned from future participation.

  • By submitting a comment, you grant us the right to publish and edit it as needed, whilst retaining your ownership of the content. Your email address will never be published or shared, though it is required for moderation purposes.