Skip to content

Instantly share code, notes, and snippets.

@dteoh
dteoh / keybase.md
Created February 4, 2015 01:02
Keybase

Keybase proof

I hereby claim:

  • I am dteoh on github.
  • I am dteoh (https://keybase.io/dteoh) on keybase.
  • I have a public key whose fingerprint is 981E AFFF 4AE6 5ED3 AC3E 401E 8498 2F30 A58D F5CB

To claim this, I am signing this object:

@dteoh
dteoh / hash_to_numeric.rb
Last active March 22, 2016 07:36
Get numeric value from hash digest
require 'digest'
key = 'the value to hash'
num = Digest::MD5.digest(key).unpack('L').first
@dteoh
dteoh / par_checksum.md
Last active February 1, 2017 11:14
Checksumming backups

par2 is not just for checksumming and recovering Usenet binaries, you can use it for your backups as well.

In my case, I wanted to make sure my RAW and JPG files don't get corrupted by bitrot.

Generating the checksum:

$ cd /the/directory/where/files/are/kept
$ par2 c something.par2 *
$ shasum -a 256 * > shasum256.txt
@dteoh
dteoh / puma_rb_backtrace.txt
Created April 10, 2017 00:05
Puma rb_backtrace() crash in lldb
(lldb) expression (void) rb_backtrace()
/Users/dteoh/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.8.2/lib/puma/plugin/tmp_restart.rb:22: [BUG] pthread_cond_wait: Invalid argument (EINVAL)
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
@dteoh
dteoh / rails_5_engine_tests.md
Last active April 28, 2018 03:31
Adding extra test paths to Rails 5 `rails test` command

In Rails 4.x, you could add extra test paths to rake test by overriding the Rake task like so:

Rake::Task['test:run'].clear

namespace :test do
  Rails::TestTask.new(:run) do |t|
    paths = ['test/**/*_test.rb']
    paths << 'engines/foo_engine/test/**/*_test.rb'
@dteoh
dteoh / records-and-bs-json.md
Last active April 2, 2019 01:31
A pattern for encoding records with bs-json

A pattern for encoding records with bs-json

If you have a record type like:

type post = {
  title: string,
  body: string,
};
@dteoh
dteoh / macos_no_sleep.md
Created February 23, 2017 23:23
Preventing macOS from sleeping

There is a built-in command line utility caffeinate that can be used to prevent macOS from sleeping.

To prevent macOS from sleeping before a process with given PID exits:

$ caffeinate -w PID

To prevent macOS from sleeping for the next N seconds:

@dteoh
dteoh / cors-curl.md
Created September 26, 2019 23:56
Check CORS headers with `curl`
$ curl -X OPTIONS -H “Origin: REQUESTER-DOMAIN.com” -H “Access-Control-Request-Method: GET“ -s -v <TARGET URL HERE> 1> /dev/null
@dteoh
dteoh / dictionary.md
Created October 23, 2019 03:13
Display dictionary definition on macOS
  1. Move mouse cursor to point at a word
  2. Press Command + Ctrl + D
@dteoh
dteoh / custom_ar_relation_relay_connection.rb
Last active October 28, 2019 16:51
GrapQL Ruby: Custom Relay connection class for ActiveRecord::Relation objects
# This custom relay connection class exists because the built-in connection
# class is broken when max_page_size is used.
#
# See: https://github.com/rmosolgo/graphql-ruby/issues/1109
class CustomArRelationRelayConnection < GraphQL::Relay::BaseConnection
def cursor_from_node(item)
cursor_col = item.class.implicit_order_column
encode(item.send(cursor_col).to_s)
end