Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@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()
" Remap the 'Enter' key to process the command line before executing
cnoremap <cr> <c-r>=<SID>DoSomeChecks()<cr><cr>
function! s:DoSomeChecks()
let g:debug = getcmdline()
" and some more stuff...
" :doautocmd with a custom event maybe?
return ''
endfunction
" <space>x -> :X
" For easier typing of custom commands
noremap <space> :call <SID>SpaceMapping()<cr>
function! s:SpaceMapping()
echo
let c = nr2char(getchar())
call feedkeys(':'.toupper(c))
endfunction
require 'pp'
class Monad
class Wrapper
def initialize(monad)
@monad = monad
@lets = {}
end
def let(name, value)
" Toggle settings:
command! -nargs=+ MapToggle call s:MapToggle(<f-args>)
function! s:MapToggle(key, opt)
let cmd = ':set '.a:opt.'! \| set '.a:opt."?\<CR>"
exec 'nnoremap '.a:key.' '.cmd
endfunction
" To toggle search highlighting on and off with <F9>, just do:
"
" MapToggle <F9> hlsearch
#! /usr/bin/env ruby
# Generate all tags for all gems included by bundler in gems.tags
#
# Basically does the same as "bundle show gemname", except for all gems.
# Interestingly enough, "bundle show" without any arguments falls back to
# "bundle list", otherwise the whole thing could have been a bash one-liner.
require 'bundler'
@AndrewRadev
AndrewRadev / fs_buffer_menu.vim
Created April 23, 2011 16:29
NERDTree plugin for filesystem manipulation using a temporary buffer for its input
" vim: foldmethod=marker
"
" This NERDTree plugin adds a filesystem manipulation menu almost exactly like
" the default one. The difference is that operations that require entering a
" file path, namely "add", "move" and "copy", use a separate one-line buffer
" to receive the input, instead of the default vim dialog. This allows you to
" use vim keybindings to move around the file path.
"
" Most of the code here is taken directly from Marty Grenfell's original
" fs_menu plugin, which can be found here:
@AndrewRadev
AndrewRadev / not.rb
Created May 25, 2011 08:19
object.not.predicate?
if not defined? BasicObject
class BasicObject
m = %w"__id__ __send__ instance_eval == equal?"
(instance_methods - m).each{|m| undef_method(m)}
end
end
class NotDelegator < BasicObject
def initialize(obj)
@_object = obj
@AndrewRadev
AndrewRadev / ordered_hash_wtf.rb
Created May 27, 2011 08:47
Odd behaviour for pp with ActiveSupport::OrderedHash
# Ruby 1.8.7-p330
# ActiveSupport 3.0.7
require 'rubygems'
require 'active_support/ordered_hash'
require 'pp'
test = ActiveSupport::OrderedHash.new
test[:one] = 1
@AndrewRadev
AndrewRadev / inconsistency.rb
Created May 27, 2011 09:20
ActiveSupport::OrderedHash inconsistency
# Ruby 1.8.7
# ActiveSupport 3.0.7
require 'rubygems'
require 'active_support/ordered_hash'
require 'pp'
ordered = ActiveSupport::OrderedHash.new
standard = Hash.new