Skip to content

Instantly share code, notes, and snippets.

View asaaki's full-sized avatar
🦀
Oh crab!

Christoph Grabo asaaki

🦀
Oh crab!
View GitHub Profile
@asaaki
asaaki / .iex.exs
Last active February 1, 2017 16:40
Automagically alias namespaced modules on IEx shell start
Code.compiler_options(ignore_module_conflict: true)
base_dir = "web/models"
if File.exists?(base_dir) do
for model_file <- File.ls!(base_dir) do
for {mod, _bytes} <- Code.load_file(model_file, base_dir) do
Code.eval_quoted(quote(do: alias unquote(mod)), [mod: mod])
end
end
end
Code.compiler_options(ignore_module_conflict: false)
@asaaki
asaaki / bench.rb
Created January 18, 2017 13:20
[Ruby] Benchmark Performance Array#map vs. Set#map
# frozen_string_literal: true
# Gemfile:
# # frozen_string_literal: true
# source 'https://rubygems.org'
# gem 'benchmark-ips'
require 'bundler/setup'
require 'benchmark/ips'
require 'set'
@asaaki
asaaki / keybase.md
Created May 8, 2016 17:16
keybase.md

Keybase proof

I hereby claim:

  • I am asaaki on github.
  • I am asaaki (https://keybase.io/asaaki) on keybase.
  • I have a public key ASBo4idVp9JxHEySo-IQ8g3-CFIvbUj93GGL_H8j8YpURwo

To claim this, I am signing this object:

@asaaki
asaaki / tap_with_conditional_return.rb
Created February 10, 2016 14:20
Poor Man's TapWithConditionalReturn
[some_data.fetch('a_string', fallback_string)].reduce(replacer) { |r, s| s == criteria ? r : s }
# or a way simpler workaround:
(origin = some_data.fetch('a_string', fallback_string)) == criteria ? replacer : origin
@asaaki
asaaki / challenge.md
Last active November 27, 2015 12:47
FastCrossing (code challenge)

N people come to a river in the night. There is a narrow bridge, but it can only hold two people at a time. The have one torch and, because it's night, the torch has to be used when crossing the bridge. Each person takes a variable amount of time to cross.

When two people cross the bridge together, they must move at the slower person's pace.

The question is, how fast can you get N people across the bridge?

(Found via ).

@asaaki
asaaki / delete-merged-branches.sh
Created November 11, 2015 16:04
Delete all merged branches
# Excludes the active branch + master and production
git branch --merged | \
grep -v -e "\*" -e master -e production | \
xargs -n1 git branch -d
@asaaki
asaaki / m💩.rb
Last active August 16, 2021 12:18
M💩.🔫 #=> 💥
module M💩
module_function
def 🔫
puts '💥'
end
end
M💩.🔫
@asaaki
asaaki / jemalloc.sh
Last active September 19, 2015 14:22
jemalloc + ruby
# path to the jemalloc shared lib
LD_PRELOAD=/usr/lib/libjemalloc.so bundle exec rails server
# Also see: https://github.com/kzk/jemalloc-rb/issues/3
@asaaki
asaaki / thread_wait_lock.rb
Last active September 5, 2015 15:03
thread_wait_lock.rb
# Condensed from http://blog.arkency.com/2015/09/testing-race-conditions/
wait_lock = true
threads = 5.times.map do |i|
Thread.new do
:noop while wait_lock # shortest no-op loop with break. Nice!*
begin
puts "Hooray from thread #{i}!" # Your awesome thread business logic here
@asaaki
asaaki / absolute.sh
Created August 28, 2015 14:58
Absolute final directory path of origin script
#!/bin/sh
# Shamelessly stolen from:
# https://github.com/michaeldfallen/git-radar/blob/master/git-radar#L7-L13
if [[ "$OSTYPE" == *darwin* ]]; then
READLINK_CMD='greadlink'
else
READLINK_CMD='readlink'
fi