Skip to content

Instantly share code, notes, and snippets.

View henrik's full-sized avatar

Henrik Nyh henrik

View GitHub Profile
@joakimk
joakimk / separate_id_series.rb
Created April 13, 2012 10:39
RSpec: Separates id series for each table so that tests does not accidentally pass when rows in different tables have the same ID
class RSpec::SeparateIdSeries
# Separates id series for each table so that tests does not
# accidentally pass when rows in different tables have the same ID
def self.setup
# This takes almost a second when using spork for some reason, so skipping it there.
return if Spork.using_spork?
t = Time.now
tables.each_with_index do |table, i|
@monde
monde / honeybadger_resque.rb
Created August 4, 2012 05:09
Honeybadger based error reporting backend for Resque
# for Rails place in config/initializers/honeybadger_resque.rb
%w( resque honeybadger ).each do |gem|
begin
require gem
rescue LoadError
raise "Can't find '#{gem}' gem. Please add it to your Gemfile or install it."
end
end
@joakimk
joakimk / Rakefile
Created October 2, 2012 11:24
Try to run no-rails rake tasks first and fallback to rails when none is found.
#!/usr/bin/env rake
# If the code below fails, uncomment this. There are no known issues now, but we had one.
#require File.expand_path('../config/application', __FILE__)
#Auctionet::Application.load_tasks
#require File.expand_path('../lib/tasks/no_rails', __FILE__)
#__END__
# Load all non-rails tasks.
path = File.expand_path('../lib/tasks/no_rails', __FILE__)
@bloudermilk
bloudermilk / tmux_clipboard
Created November 5, 2012 21:59
A program for syncing the tmux clipboard with OS X's
#!/bin/sh
# Stolen from Joshua Clayton of thoughtbot:
# http://robots.thoughtbot.com/post/19398560514/how-to-copy-and-paste-with-tmux-on-mac-os-x
PATH=/usr/local/bin:$PATH
while true; do
if test -n "`tmux showb 2> /dev/null`"; then
tmux saveb - | pbcopy && tmux deleteb
" The Vim search-and-replace we use in migrating from Fabrication to FactoryGirl.
" Change "name_of_factory" to the name.
:%s/\vFabricate(.build)?(\(:(name_of_factory)[,)])/FactoryGirl\1\2/e | %s/FactoryGirl(/FactoryGirl.create(/e
@henrik
henrik / rules.md
Last active May 23, 2022 12:31
Sandi Metz' four rules from Ruby Rogues episode 87. Listen or read the transcript: http://rubyrogues.com/087-rr-book-clubpractical-object-oriented-design-in-ruby-with-sandi-metz/
  1. Your class can be no longer than 100 lines of code.
  2. Your methods can be no longer than five lines of code.
  3. You can pass no more than four parameters and you can’t just make it one big hash.
  4. When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done. And your view can only know about one instance variable.

You can break these rules if you can talk your pair into agreeing with you.

@bloudermilk
bloudermilk / porvo.md
Last active December 12, 2015 04:18
PORVO: Plain old Ruby view objects (draft)
method PageHeaderHelper
  def page_header(title, subtitle = nil, &contents)
    PageHeader.new(self, title, subtitle, &contents)
  end

  class PageHeader
    attr_reader :context, :title, :subtitle

    def initialize(context, title, subtitle = nil)
@mislav
mislav / fat-logfiles.sh
Last active June 6, 2025 19:18
Find "*.log" files in your home dir, sort them by fattest-first, and calculate the size of them all together.
find ~ -name '*.log' -print0 | xargs -0 -L1 stat -f'%z %N' | sort -rn | tee fat-logfiles.txt | head
awk '{ total += $1 } END { printf "total: %5.2f MiB\n", total/1024/1024 }' < fat-logfiles.txt
@mislav
mislav / _readme.md
Last active July 22, 2025 23:54
tmux-vim integration to transparently switch between tmux panes and vim split windows

I use tmux splits (panes). Inside one of these panes there's a Vim process, and it has its own splits (windows).

In Vim I have key bindings C-h/j/k/l set to switch windows in the given direction. (Vim default mappings for windows switching are the same, but prefixed with C-W.) I'd like to use the same keystrokes for switching tmux panes.

An extra goal that I've solved with a dirty hack is to toggle between last active panes with C-\.

Here's how it should work:

@atenni
atenni / README.md
Last active August 13, 2025 10:45
How to permalink to a gist's raw file

Problem: When linking to the raw version of a gist, the link changes with each revision.

Solution:

To return the first file from a gist: https://gist.github.com/[gist_user]/[gist_id]/raw/

To get a file from multi–file gist: https://gist.github.com/[gist_user]/[gist_id]/raw/[file_name]