Skip to content

Instantly share code, notes, and snippets.

View jimeh's full-sized avatar

Jim Myhrberg jimeh

View GitHub Profile
@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 / 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:

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 / 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"
@jimeh
jimeh / weight.rb
Created July 16, 2009 07:14
weight.rb (RoR): Lets you pick a row from a table randomly based on the rows weight.
#
#
# weight.rb (A Ruby on Rails Model).
# Lets you pick a row from a table randomly based on the rows weight.
#
# Your table will need three columns:
# - weight (float)
# - weight_begin (float)
# - weight_end (float)
#
#
# The dumbest piece of code I've EVER written.
#
# I REALLY don't know WTF I was thinking, or not thinking.
# I must have been drunk and asleep while I wrote this method.
#
# It's not only stupid, but IT DOESN'T EVEN WORK! *stabs self in face*
#
def stupid_method
@jimeh
jimeh / call_parallel.rb
Created October 7, 2009 13:54
Ruby: #call_parallel
#
# Run multiple system commands in parallel
#
def call_parallel(cmds = [], check_interval = nil)
if cmds.size > 0
threads, results = [], []
cmds.each do |cmd|
threads << Thread.new { results << [cmd, `#{cmd}`, $?] }
end
is_done = false
# Dump database "hello_world"
$ ./dump_to_s3.rb hello_world
dumping hello_world database...
uploading /mnt/hello_world-2009-10-30_12-11-44.sql_aa to S3.
uploading /mnt/hello_world-2009-10-30_12-11-44.sql_ab to S3.
uploading /mnt/hello_world-2009-10-30_12-11-44.sql_ac to S3.
@jimeh
jimeh / _NOTE.md
Created November 16, 2009 00:16
My Git related config and aliases

NOTE

This gist is now deprecated as I've finally sorted out and made my dotfiles public.

My ~/.gitconfig is available here, and my git-related shell setup here.

require "rubygems"
require "friendly"
require "models/user"
Friendly.configure(
:adapter => "mysql",
:host => "localhost",
:user => "root",
:password => "boot",
:database => "friendlyplay"