Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@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");
}
@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
@AndrewRadev
AndrewRadev / utl_mapping.vim
Created October 10, 2009 14:39
NERDTree integration with Utl
" Requires: Utl
call NERDTreeAddKeyMap({
\ 'key': 'gu',
\ 'callback': 'OpenCurrentNodeWithUtl',
\ 'quickhelpText': 'open current node with the Utl plugin' })
function! OpenCurrentNodeWithUtl()
" Get the path of the item under the cursor if possible:
let currentDir = g:NERDTreeFileNode.GetSelected()
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('.'))
@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,
@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
@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:
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:29
Focus on specific specs in RSpec
# add this to your spec helper
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
# and then use the :focus tag in your specs
it "does something awesome", :focus do
@hdeshev
hdeshev / .ctags
Created October 9, 2011 21:58
My Scala-enabled ctags config
--langdef=scala
--langmap=scala:.scala
--regex-scala=/^[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\1/c,classes/
--regex-scala=/.*class[ \t]+([a-zA-Z0-9_]+)/\1/c,classes/
--regex-scala=/^[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\1/t,traits/
--regex-scala=/.*trait[ \t]+([a-zA-Z0-9_]+)/\1/t,traits/
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t]*def[ \t]+([a-zA-Z0-9_\?]+)/\1/m,methods/
--regex-scala=/^[ \t]*val[ \t]+([a-zA-Z0-9_]+)/\1/C,constants/
--regex-scala=/^[ \t]*var[ \t]+([a-zA-Z0-9_]+)/\1/l,local variables/
@skanev
skanev / debug.rb
Created November 3, 2011 14:17
Debugging the performance of a Rails controller action
require 'rails/console/app'
ActiveSupport::Notifications.subscribe /^sql\./ do |*args|
puts caller.grep(%r[/garmz/]) { |line| " #{line.gsub(/.*?\/garmz\//, '')}" }.take(3) * "\n"
end
ActiveRecord::Base.logger = Logger.new(STDOUT)
app.get '/newsfeed'
ActiveRecord::Base.logger = Logger.new(nil)