Skip to content

Instantly share code, notes, and snippets.

Douglas Teoh dteoh

Block or report user

Report or block dteoh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dteoh
dteoh / neovim_python.md
Created Jun 26, 2019
NeoVim + Python 3 provider
View neovim_python.md

Assuming that [Conda][1] is used, start by creating an environment for NeoVim:

$ conda create -n neovim36 python=3.6

Fish shell users:

$ source (conda info --root)/etc/fish/conf.d/conda.fish  
@dteoh
dteoh / unused-this.md
Last active Apr 17, 2019
Solving "unused variable this." warnings when using ReasonML objects
View unused-this.md

unused variable this

You can create [objects in ReasonML][1]. For example:

let document = {
  pub title = "My Treatise";
  pub contents = "<a lot of words>"
};
@dteoh
dteoh / records-and-bs-json.md
Last active Apr 2, 2019
A pattern for encoding records with bs-json
View records-and-bs-json.md

A pattern for encoding records with bs-json

If you have a record type like:

type post = {
  title: string,
  body: string,
};
@dteoh
dteoh / .gitconfig
Created Mar 17, 2019
Use Neovim as git mergetool
View .gitconfig
[merge]
tool = vimdiff
[mergetool]
keepBackup = false
[mergetool "vimdiff"]
cmd = nvim -d $LOCAL $REMOTE $MERGED -c '$wincmd w' -c 'wincmd J'
@dteoh
dteoh / puma_rb_backtrace.txt
Created Apr 10, 2017
Puma rb_backtrace() crash in lldb
View puma_rb_backtrace.txt
(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 / macos_no_sleep.md
Created Feb 23, 2017
Preventing macOS from sleeping
View macos_no_sleep.md

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 / rails_5_engine_tests.md
Last active Apr 28, 2018
Adding extra test paths to Rails 5 `rails test` command
View rails_5_engine_tests.md

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 / put_post_json_rails_5_integration_test.md
Created Jul 12, 2016
PUT or POST JSON in a Rails 5 ActionDispatch::IntegrationTest
View put_post_json_rails_5_integration_test.md

In Rails 5, the preferred base class for testing controllers is ActionDispatch::IntegrationTest.

If you have an API that receives parameters as JSON request bodies, here are some helper methods to facilitate testing:

class ActionDispatch::IntegrationTest
  def put_json(path, obj)
    put path, params: obj.to_json, headers: { 'CONTENT_TYPE' => 'application/json' }
  end
@dteoh
dteoh / hash_to_numeric.rb
Last active Mar 22, 2016
Get numeric value from hash digest
View hash_to_numeric.rb
require 'digest'
key = 'the value to hash'
num = Digest::MD5.digest(key).unpack('L').first
@dteoh
dteoh / par_checksum.md
Last active Feb 1, 2017
Checksumming backups
View par_checksum.md

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
You can’t perform that action at this time.