Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@schacon
schacon / ruby_c_ext.txt
Created December 19, 2010 06:46
Ruby C Extension Articles
README.ext
http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v1_8_6/README.EXT?revision=12055
Extending Ruby - Pickaxe
http://ruby-doc.org/docs/ProgrammingRuby/html/ext_ruby.html
Extending Ruby on O'Reilly
http://onlamp.com/pub/a/onlamp/2004/11/18/extending_ruby.html
Ruby C Extensions - Mark Volkman
@henrik
henrik / jquery.checkboxes.js
Last active October 24, 2017 12:01
jQuery checkbox utilities: check range, master toggle box, check/uncheck all.
// jQuery checkbox utility plugin.
// Triggers "change" events on the checkboxes.
// By Henrik Nyh <http://henrik.nyh.se> 2009-04-27 under the MIT License.
(function($) {
function makeChecked($checkboxes, checked) {
return $checkboxes.prop("checked", checked).trigger("change");
}
@searls
searls / market_research.rb
Last active September 18, 2018 03:21
Was chatting with @mfeathers about retaining Ruby's chained Enumerable style, but finding a way to inject names that reflects the application domain (as opposed to just littering functional operations everywhere, which may be seen as a sort of Primitive Obsession)
# A little toy file demonstrating how to build chainable
# data transformations that reveal some amount of intent
# through named extracted methods.
#
# Kudos to @mfeathers for giving me the idea to try this
#
# Copyright Test Double, LLC, 2016. All Rights Reserved.
require_relative "marketing_refinements"
@henrik
henrik / commit-msg
Created September 10, 2009 18:25
Git commit-msg hook that automatically adds "Refs #123" when in the branch t123, "[#123]" when in the branch s123 etc.
#!/usr/bin/env ruby
#
# Git commit-msg hook. If your branch name is in the form "t123", automatically
# adds "Refs #123." to commit messages unless they mention "#123" already.
# Include "#close" or "#finish" to add "Closes #123."
#
# For Pivotal Tracker, branch names like "s123" adds "[#123]".
# Include "#close" or "#finish" to add "[Finishes #123]".
#
# If you include "#noref" in the commit message, nothing will be added to
@nathansmith
nathansmith / if-poem.md
Last active July 18, 2021 23:20
"IF" by Rudyard Kipling
If you can keep your head when all about you
Are losing theirs and blaming it on you,
If you can trust yourself when all men doubt you
But make allowance for their doubting too,
If you can wait and not be tired by waiting,
Or being lied about, don't deal in lies,
Or being hated, don't give way to hating,
And yet don't look too good, nor talk too wise:
@skanev
skanev / autocomplete_from_tmux.sh
Created February 1, 2012 09:41
zsh: autocomplete words in current tmux session
# Autocomplete from current tmux screen buffer
_tmux_pane_words() {
local expl
local -a w
if [[ -z "$TMUX_PANE" ]]; then
_message "not running inside tmux!"
return 1
fi
w=( ${(u)=$(tmux capture-pane \; show-buffer \; delete-buffer)} )
_wanted values expl 'words from current tmux pane' compadd -a w
@nathansmith
nathansmith / html_reset.css
Created January 28, 2010 00:02
Reset for HTML4 / HTML5
/* `XHTML, HTML4, HTML5 Reset
----------------------------------------------------------------------------------------------------*/
a,
abbr,
acronym,
address,
applet,
article,
aside,
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
@othree
othree / switchCase.vim
Created May 27, 2013 07:08
Switch between different case type: camelCase -> MixedCase -> snake_case -> UPPER_CASE -> dash-case -> camelCase
let g:switch_custom_definitions =
\ [
\ {
\ '\<\(\l\)\(\l\+\(\u\l\+\)\+\)\>': '\=toupper(submatch(1)) . submatch(2)',
\ '\<\(\u\l\+\)\(\u\l\+\)\+\>': "\\=tolower(substitute(submatch(0), '\\(\\l\\)\\(\\u\\)', '\\1_\\2', 'g'))",
\ '\<\(\l\+\)\(_\l\+\)\+\>': '\U\0',
\ '\<\(\u\+\)\(_\u\+\)\+\>': "\\=tolower(substitute(submatch(0), '_', '-', 'g'))",
\ '\<\(\l\+\)\(-\l\+\)\+\>': "\\=substitute(submatch(0), '-\\(\\l\\)', '\\u\\1', 'g')",
\ }
\ ]
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))