Skip to content

Instantly share code, notes, and snippets.

@graywh
graywh / cookie_clicker.rb
Created January 15, 2014 03:15
cookie clicker cps calculation code written in a semi-functional style
# RSpec matcher to spec delegations.
# Forked from https://gist.github.com/ssimeonov/5942729 with fixes
# for arity + custom prefix.
#
# Usage:
#
# describe Post do
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
# it { should delegate(:name).to(:author).with_prefix(:any) } # post.any_name
# it { should delegate(:month).to(:created_at) }
@graywh
graywh / gist:4126100
Created November 21, 2012 17:08
MacVim mvim installation
mkdir -p /usr/local/macvim/vim
cd /usr/local/macvim/vim
# copy MacVim's mvim script here
# and add /usr/local/macvim/vim to the beginning of /etc/paths
ln -s mvim eview
ln -s mvim evim
ln -s mvim ex
ln -s mvim exim
ln -s mvim gex
ln -s mvim gview
@graywh
graywh / gist:4091066
Created November 16, 2012 21:25
Insert tabs at beginning of line, spaces afterward
function! TabOrSpace()
let text = strpart(getline('.'), 0, col('.')-1)
if text =~ '^\t*$'
return "\<C-v>\<Tab>"
else
let l = strdisplaywidth(text)
let n = float2nr(floor(l / &l:softtabstop) + 1) * &l:softtabstop
return repeat(' ', n - l)
endif
endfunction
@graywh
graywh / input
Created October 22, 2012 16:12
Testing surround.vim's cs with multi-line braces
{
foo
bar
baz
}
(
foo
bar
baz
@graywh
graywh / gist:3439466
Created August 23, 2012 17:55
Auto-creating nested hashes via recursive proc
hash = lambda { |h, k| h[k] = Hash.new &hash }
x = Hash.new &hash
x[1][2][3][4][5] = 6
x #=> {1=>{2=>{3=>{4=>{5=>6}}}}}
@graywh
graywh / gist:2586886
Created May 3, 2012 16:16
Fix Irssi key bindings
--- irssi-0.8.15.orig/src/fe-text/gui-readline.c
+++ irssi-0.8.15/src/fe-text/gui-readline.c
@@ -392,12 +392,6 @@
str[g_unichar_to_utf8(key, str)] = '\0';
}
- if (strcmp(str, "^") == 0) {
- /* change it as ^^ */
- str[1] = '^';
- str[2] = '\0';
@graywh
graywh / gist:2586878
Created May 3, 2012 16:15
Disable cwd detection via /proc
--- tmux-1.6.orig/cmd.c
+++ tmux-1.6/cmd.c
@@ -1235,11 +1235,11 @@ cmd_get_default_path(struct cmd_ctx *ctx
if (*cwd == '\0') {
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
return (ctx->cmdclient->cwd);
- if (ctx->curclient != NULL) {
- wp = s->curw->window->active;
- if ((cwd = osdep_get_cwd(wp->pid)) != NULL)
- return (cwd);
@graywh
graywh / app_models_asset.rb
Created February 13, 2012 17:27
ActiveRecord 3.0.9 error -- has_one :through a has_one with :conditions
class Asset < ActiveRecord::Base
has_many :ownerships
has_many :owners, :through => :ownerships
has_one :current_ownership, :class_name => Ownership.name, :conditions => { :current => true }
has_one :current_owner, :through => :current_ownership, :source => :owner
end
function! Test()
try
silent !watch -n 1 date
catch
endtry
redraw!
endfunction