TIL about scheduling timed jobs on MacOS through launchd.

Each launchd job is described by a separate plist file, meaning you can manage launchd timed jobs by simply adding or removing a file. These files should be placed in certain folders according to the goal of the job:

  • System tasks go to:

if they need to run no matter if a user is logged in to the system or not. These tasks will be started with “root” privileges.

  • If they need to run if any user is logged in, they go to:

and will be executed with the privileges of the user that just logged in.

  • If they need to run if only you are logged in, they go to:

The documentation can be found here. Examples of timed jobs can be found here.

TIL about Floyd’s Tortoise and Hare algorithm.

This algorithm is used to detect whether there is a cycle in a list, and given that a cycle exists its starting point and the length of the cycle.

The algorithm can also be used to prove the existence of duplicate numbers in a list.

The time complexity of this algorithm is linear: O(n).
The space complexity of this algorithm is constant: O(1).

TIL that we can disable gems when loading a Ruby script through --disable=gems.

$ ruby --disable=gems -e ''

TIL that we can get optimized assembly output from a Cargo project by running the following command:

cargo rustc --release -- --emit asm

This will output x86 by default, but say we wanted the intel syntax?

cargo rustc -- --emit asm -C "llvm-args=-x86-asm-syntax=intel"

TIL that Rust closures creates an anonymous struct in order to represent their environment. As an example:

let a = 42;
let b = 100;
let f = |v: i32| v + a + b;

would be represented as something like:

struct __anonymous_e3b0105<'a> {
    a: &'a i32,
    b: &'a i32,

TIL about recursive macros in vim. As the name implies, it consists of calling your macro within the macro your are building. Pre-requisites:

  1. Having a clear register (qa -> q to clear register a)
  2. Having a break point through t or f if we don’t want to run on all lines

Suppose we have the following file:

 1  abc,123
 2  bcd,4
 3  cde,54321
 4  def,88

And we want the end result to be:

hash["abc"] = 123
hash["bcd"] = 4
hash["cde"] = 54321
hash["def"] = 88

In order to build our recursive macro:

qa Start macro
02cw Go to beginning of line and change two words
hash"[<esc>  Insert hash[" characters and exit normal mode
f, Find the next , character
i"] = <esc> Insert "] = characters and exit normal mode
lx Move left and delete a character (the , in this case)
j Go to the line below
@a Call your macro. This creates the recursion
q Finish macro

After that calling @a will change every line.

TIL about the flock system call which applies or removes an advisory lock on an open file. The thing to pay attention is the word advisory, other processes can ignore this lock if they wish to do so. This syscall will lock the entire file, which can be pretty bad for highly concurrent systems.

For more information: man 2 flock

For a more fine grained locking mechanism: man 2 fcntl

TIL about the FromStr trait in Rust that is implicitly used through str’s parse method.

We could have a struct called Period that parses a string like: “10 days” into Period { value: 10, timeframe: "days" }. The way to use it would be:

let period = "10 days".parse::<Period>();

TIL about the term cookie tossing, an attack leverages the feature that a subdomain can put a key=value pair in a cookie which can then also be read by the domain above it. For example, todayilearned.dev doesn’t know if this key comes from it or from cookie.todayilearned.dev.

This becomes problematic when a website allows untrusted people to host subdomains under its domain. They can then abuse this feature to write manipulated cookie information.

Copied to clipboard