Code Snippets

All Snippets

The latest code snippets.

Recursive Glob in Ruby

Find every `.rb` file under a tree with Dir.glob and `**` recursion.

Author: chris

Sort Array of Hashes by Key

Sort an array of hashes by a numeric attribute using sort_by.

Author: chris

Generate SHA256 Hash in Ruby

Compute the SHA256 hex digest of any string with Digest::SHA256.

Author: chris

Parse and Generate JSON in Ruby

Parse a JSON string into a Hash and convert back with the json stdlib.

Author: chris

HTTP GET with Net::HTTP

Stdlib HTTP GET request using Net::HTTP and URI.

Author: chris

Read a File into a String

Slurp an entire file into a string with File.read, the idiomatic Ruby way.

Author: chris

Fork a Child Process in Perl

Spawn a child process with fork() and wait for it to exit.

Author: chris