Skip to content

Instantly share code, notes, and snippets.

View iboard's full-sized avatar
🏠
Crafting beautiful code at home

Andreas Altendorfer iboard

🏠
Crafting beautiful code at home
View GitHub Profile
@iboard
iboard / fizz_buz.rb
Last active January 20, 2019 07:57
Benchmarking if versus map-matching (a kind of pattern-matching in ruby)
require "benchmark"
def log msg
# NOOP
end
def with_if(x)
x.times do |n|
if (n % 3 == 0) && (n % 5 != 0)
log 'Fizz'
@iboard
iboard / run_ruby.vim
Last active January 20, 2019 07:53
Run the current line in vim with rspec
" Call rspec from vim
" Apr 21st, 2014 Andi Altendorfer <[email protected]>, License MIT
"
" RunCurrentLine() ... evaluate current line with ruby-interpreter and append " output to the end of the line
" RunCurrentFile() ... evaluate current file with ruby-interpreter and append " output to the end of the file
"
" Copy this file to your ./vim/pluglin directory
function! RunCurrentLine ()
exec "normal! $F#D"
let _current_line = getline(".")
@iboard
iboard / rspec-vim.vim
Last active January 20, 2019 07:58
Vim-functions to run rspec from current file, line
" Call rspec from vim
" Apr 21st, 2014 Andi Altendorfer <[email protected]>
"
" RspecLine() ... run rspec for the current cursor line
" RspecFile() ... run rspec for the current file
" RspecAll() .... run entire suite
"
" Copy this file to your ./vim/pluglin directory
function RspecLine()
@iboard
iboard / rspec-vim.vim
Created April 21, 2014 06:47
Run rspec from vim
" Call rspec from vim
" Apr 21st, 2014 Andi Altendorfer <[email protected]>
"
" RspecLine() ... run rspec for the current cursor line
" RspecFile() ... run rspec for the current file
" RspecAll() .... run entire suite
"
" Copy this file to your ./vim/pluglin directory
function RspecLine()
@iboard
iboard / ruby_sort_exceptions.rb
Last active January 20, 2019 07:59
Stackoverflow-example
require 'ostruct'
# ad 1)
def sort_descending1 _objects, field
_objects.sort { |b,a| a.send(field) <=> b.send(field) }
end
# ad 2)
def safe_compare2 a,b,field
a.send(field) <=> b.send(field)
@iboard
iboard / wombatAndi.vim
Last active January 20, 2019 08:00
My vim colors
" Vim color file
" Original Maintainer: Lars H. Nielsen ([email protected])
" Last Change: 2010-07-23
"
" Converting for 256-color terminals by
" Danila Bespalov ([email protected])
" with great help of tool by Wolfgang Frisch ([email protected])
" inspired by David Liang's version ([email protected])
set background=dark
@iboard
iboard / tr_on_click.coffee
Created June 16, 2013 12:45
Handle click on a table-row with Rails4 and coffeescript
# WORKS THE FIRST TIME BUT FAILES WHEN RETURNING TO THE PAGE UNLESS RELOADING
jQuery ->
$('.clickable-row td').click ->
target_id = $(this).parent().attr('id').replace /row-id-/,''
document.location = "/controller_xy/#{target_id}/edit"
# WORKS FINE EVERY TIME
jQuery ->
$(document).on( 'click', '.clickable-row td', ->
@iboard
iboard / ruby-destructor-example.rb
Last active March 21, 2025 09:32
Ruby 'Destructor' example.
class Foo
attr_reader :bar
def initialize
@bar = 123
ObjectSpace.define_finalizer( self, self.class.finalize(bar) )
end
def self.finalize(bar)
proc { puts "DESTROY OBJECT #{bar}" }
end
@iboard
iboard / .tmux.conf
Last active January 20, 2019 08:02
My .tmux-config for Mac OS X, iTerm2
set-window-option -g utf8 on
set -g mode-mouse on
set -g mouse-resize-pane on
set -g mouse-select-pane on
set -g mouse-select-window on
set-option -g prefix C-q
set -g history-limit 50000
unbind-key C-b
bind-key q send-prefix
set -g base-index 1
@iboard
iboard / run_tags
Last active January 20, 2019 08:03
# A script to run ctags on all .rb files in a project
#!/usr/bin/env ruby
#-*-ruby-*-
# A script to run ctags on all .rb files in a project. Can run on
# the current dir, called from a git callback, or install itself as a
# git post-merge and post-commit callback.
CTAGS = '/usr/local/bin/ctags'
HOOKS = %w{ post-merge post-commit post-checkout }
HOOKS_DIR = '.git/hooks'