Skip to content

Instantly share code, notes, and snippets.

View jimeh's full-sized avatar

Jim Myhrberg jimeh

View GitHub Profile
@jimeh
jimeh / code.rb
Last active August 29, 2015 14:25
Weird Ruby variable assignment behavior
puts defined?(hello).inspect # => nil
puts "this will not print #{hello.inspect}" rescue nil
hello = 'dude' if false
puts defined?(hello).inspect # => "local-variable"
puts hello.inspect # => nil
# Outputs:
#
# nil
# "local-variable"

Keybase proof

I hereby claim:

  • I am jimeh on github.
  • I am jimeh (https://keybase.io/jimeh) on keybase.
  • I have a public key whose fingerprint is F0FD DA8B 81F8 3800 1ADF E59E B85A 9E6D 6BBB 670E

To claim this, I am signing this object:

@jimeh
jimeh / Growing my RAID on Mordor.md
Last active August 29, 2015 14:14
Personal notes from last time I added a disk to my RAID, so I've one got compact place to find all steps next time.
  1. Prepare disk with gparted:
  2. Terminal: - sudo DISPLAY=:5 gparted
  3. Device > Create Partition Table: - Partition table type: gpt
  4. Partition > New: - Create as: Primary Partition - File system: ext4
  5. Edit > Apply All Operations
  6. Partition > Manage flags:
@jimeh
jimeh / log_current_url_step.rb
Last active August 29, 2015 14:06
Crazy hack way to debug Cucumber runs in PhantomJS with a real browser.
# Visit printed URL in a real browser. When done press enter/return to resume
# Cucumber run.
Then(/^log current URL$/) do
STDOUT.print " >>>>>> current_url: #{current_url}"
STDIN.gets
end
@jimeh
jimeh / zsh-history-search-with-peco.zsh
Last active July 16, 2022 17:12
Use peco (https://github.com/peco/peco) to search ZSH's history via ctrl+R
# Search shell history with peco: https://github.com/peco/peco
# Adapted from: https://github.com/mooz/percol#zsh-history-search
if which peco &> /dev/null; then
function peco_select_history() {
local tac
(which gtac &> /dev/null && tac="gtac") || \
(which tac &> /dev/null && tac="tac") || \
tac="tail -r"
BUFFER=$(fc -l -n 1 | eval $tac | \
peco --layout=bottom-up --query "$LBUFFER")
@jimeh
jimeh / p2pool
Last active January 12, 2018 13:26
Quickly hacked together init.d script for p2pool.
#!/bin/sh
### BEGIN INIT INFO
# Provides: p2pool
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: p2pool startup script
# Description: p2pool startup script
### END INIT INFO
@jimeh
jimeh / emacs-osx-srgb.patch
Last active December 25, 2015 01:58 — forked from purcell/emacs-osx-srgb.patch
Adjusted for Emacs 24.3 source specifically
diff --git a/src/nsterm.m b/src/nsterm.m
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1401,7 +1401,7 @@ ns_get_color (const char *name, NSColor
if (r >= 0.0)
{
- *col = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0];
+ *col = [NSColor colorWithSRGBRed: r green: g blue: b alpha: 1.0];
UNBLOCK_INPUT;
@jimeh
jimeh / stub.bash
Last active February 16, 2022 23:00
Shell script helpers to stub and restore bash shell functions/commands in tests.
# Stub commands printing it's name and arguments to STDOUT or STDERR.
stub() {
local cmd="$1"
if [ "$2" == "STDERR" ]; then local redirect=" 1>&2"; fi
if [[ "$(type "$cmd" | head -1)" == *"is a function" ]]; then
local source="$(type "$cmd" | tail -n +2)"
source="${source/$cmd/original_${cmd}}"
eval "$source"
fi
@jimeh
jimeh / camper_van
Last active December 16, 2015 23:29
Quickly hacked together init.d script for the camper_van gem.
#! /bin/sh
### BEGIN INIT INFO
# Provides: skeleton
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.