flock CLI (Python3)

Applies (or removes) an advisory lock on a specified file

Although it doesn't have feature-parity, the script is compatible with flock(1).

The script was created because, although the OS has the relevant API (i.e. flock(2)), Mac OS doesn't have the flock cli utility.

This script provides a (mostly) drop-in cross-platform option.

The script only supports acquiring exclusive locks (in blocking or non-blocking mode)

Read more…

Have the find Command Invoke A Custom Shell Function (BASH)

The find command accepts and -exec argument, allowing you to pass matching files into an arbitrary command.

It's pretty useful, but sometimes you want to be able to have it invoke a custom function, which it can't do without a little bit of tweaking

This snippet details how to have find invoke a custom shell function against each matching result, the example uses BASH but the same should be possible with ZSH, DASH, ASH, KSH etc

Read more…

Calculating the Total Time Spent In A State (Flux)

Flux's stdlib provides the function StateDuration() which adds a column with an incrementing counter for as long as the data matches the provided predicate (i.e. indicates a specific state).

However, this counter resets when the state changes, so the duration column only tells you how long each instance of the state lasted and because the counter is added to each row, you cannot simply sum() it to calculate the total time spent in that state (say a switch being on)

However, it's possible to calculate the total amount of time spent in a state using the elapsed()function with a map().

This snippet details how to define a set of predicate based states for a stream of data and then calculate the total time spent in each of those states

Read more…

Constructing a hyperlink to share content onto Facebook (Misc)

Nowadays, most sites will find that the majority of their traffic arrives as the result of someone else sharing or "likeing" the content on Social Media. As a result, it's desirable to make the act of sharing as easy as possible.

The various social networks often provide "share this" widgets that can be embedded into sites. However, these involve the user's browser requesting resources from the social network, and these requests are known to be data-mined in order to track users across the web and profile their browsing habits (to better sell ads).

However, most social media networks do make it possible to create a share button which works via a simply hyperlink.

This snippet details how to construct a link which shares a page onto Facebook. However, you'll first need to sign up for a developer account and create an App so that you have a valid Opengraph app id to include in the URL.

Read more…

Constructing a hyperlink to share content onto QQ (Misc)

Nowadays, most sites will find that the majority of their traffic arrives as the result of someone else sharing or "likeing" the content on Social Media. As a result, it's desirable to make the act of sharing as easy as possible.

The various social networks often provide "share this" widgets that can be embedded into sites. However, these involve the user's browser requesting resources from the social network, and these requests are known to be data-mined in order to track users across the web and profile their browsing habits (to better sell ads).

However, most social media networks do make it possible to create a share button which works via a simply hyperlink.

This snippet details how to construct a link which shares a page onto QQ. You can see an example of how to put this into practice as a share button inside a site's template here

Read more…

Constructing a hyperlink to share content onto Telegram (Misc)

Nowadays, most sites will find that the majority of their traffic arrives as the result of someone else sharing or "likeing" the content on Social Media. As a result, it's desirable to make the act of sharing as easy as possible.

The various social networks often provide "share this" widgets that can be embedded into sites. However, these involve the user's browser requesting resources from the social network, and these requests are known to be data-mined in order to track users across the web and profile their browsing habits (to better sell ads).

However, most social media networks do make it possible to create a share button which works via a simply hyperlink.

This snippet details how to construct a link which shares a page onto Telegram. You can see an example of how to put this into practice as a share button inside a site's template here

Read more…

Constructing a hyperlink to share content onto WhatsApp (Misc)

Nowadays, most sites will find that the majority of their traffic arrives as the result of someone else sharing or "likeing" the content on Social Media. As a result, it's desirable to make the act of sharing as easy as possible.

The various social networks often provide "share this" widgets that can be embedded into sites. However, these involve the user's browser requesting resources from the social network, and these requests are known to be data-mined in order to track users across the web and profile their browsing habits (to better sell ads).

However, most social media networks do make it possible to create a share button which works via a simply hyperlink.

This snippet details how to construct a link which shares a page onto WhatsApp. You can see an example of how to put this into practice as a share button inside a site's template here

Read more…

Constructing a hyperlink to share content onto LinkedIN (Misc)

Nowadays, most sites will find that the majority of their traffic arrives as the result of someone else sharing or "likeing" the content on Social Media. As a result, it's desirable to make the act of sharing as easy as possible.

The various social networks often provide "share this" widgets that can be embedded into sites. However, these involve the user's browser requesting resources from the social network, and these requests are known to be data-mined in order to track users across the web and profile their browsing habits (to better sell ads).

However, most social media networks do make it possible to create a share button which works via a simply hyperlink.

This snippet details how to construct a link which shares a page onto LinkedIN. You can see an example of how to put this into practice as a share button inside a site's template here

Read more…

Constructing a hyperlink to share content onto Reddit (Misc)

Nowadays, most sites will find that the majority of their traffic arrives as the result of someone else sharing or "likeing" the content on Social Media. As a result, it's desirable to make the act of sharing as easy as possible.

The various social networks often provide "share this" widgets that can be embedded into sites. However, these involve the user's browser requesting resources from the social network, and these requests are known to be data-mined in order to track users across the web and profile their browsing habits (to better sell ads).

However, most social media networks do make it possible to create a share button which works via a simply hyperlink.

This snippet details how to construct a link which shares a page onto Reddit. You can see an example of how to put this into practice as a share button inside a site's template here

Read more…

Constructing a hyperlink to share content onto LINE Messenger (Misc)

Nowadays, most sites will find that the majority of their traffic arrives as the result of someone else sharing or "likeing" the content on Social Media. As a result, it's desirable to make the act of sharing as easy as possible.

The various social networks often provide "share this" widgets that can be embedded into sites. However, these involve the user's browser requesting resources from the social network, and these requests are known to be data-mined in order to track users across the web and profile their browsing habits (to better sell ads).

However, most social media networks do make it possible to create a share button which works via a simply hyperlink.

This snippet details how to construct a link which shares a page onto LINE. You can see an example of how to put this into practice as a share button inside a site's template here

Read more…