Skip to content

Instantly share code, notes, and snippets.

Andrew Radev AndrewRadev

Block or report user

Report or block AndrewRadev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@AndrewRadev
AndrewRadev / caching_decorator.rb
Last active Aug 29, 2015
Caching decorator in ruby 2.1
View caching_decorator.rb
# In ruby 2.1, the method definition returns the name of the method. As a
# result, python-decorator-like class methods can be created.
#
module CachingDecorator
def cached(method_name)
alias_method("_generate_#{method_name}", method_name)
define_method(method_name) do
@_caching_decorator_cache ||= {}
View vimberlin.md

Go support for Vim

Go is an interesting language in many respects, and one of them is tooling. Unlike many other languages, Go attempts to ship with various tools for code parsing and rewriting, to make it feasible to use IDE-like functionality with any editor or IDE, simply by invoking tools on the command-line.

I'd like to demonstrate my own fork of the Go Vim support, talk about what Google has provided and what kind of experiments I've done with it. I'll also show some interesting Go tools and how they can be integrated into Vim, like code completion, finding definitions, the "Go Oracle".

Even if you don't know anything about Go, I hope it will turn into an interesting discussion about language support and tooling in general.

View vim_version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 31 2014 17:05:36)
Included patches: 1-229
Compiled by Andrew Radev <andrey.radev@gmail.com>
Big version with GTK2 GUI. Features included (+) or not (-):
+acl +farsi +mouse_netterm +syntax
+arabic +file_in_path +mouse_sgr +tag_binary
+autocmd +find_in_path -mouse_sysmouse +tag_old_static
+balloon_eval +float +mouse_urxvt -tag_any_white
+browse +folding +mouse_xterm -tcl
++builtin_terms -footer +multi_byte +terminfo
@AndrewRadev
AndrewRadev / commented_paste.vim
Last active Aug 29, 2015
Example for the "_dd problem
View commented_paste.vim
nnoremap gp :call <SID>CommentedPaste()<cr>
function! s:CommentedPaste()
let text = getreg(v:register)
let commented_lines = []
for line in split(text, "\n", 1)
call add(commented_lines, substitute(line, '\s*\zs\S', '# \0', ''))
endfor
View switch_colors.vim
nmap <leader>bb :call <SID>SwitchColors('andrew', 'default')<cr>:echo "Colorscheme: ".g:colors_name<cr>
let s:previous_colorscheme = g:colors_name
function! s:SwitchColors(...)
let colorscheme_list = a:000
let previous_colorscheme_index = index(colorscheme_list, s:previous_colorscheme)
if previous_colorscheme_index < 0
" not found, just use the first one
View yank_filename_mapping.vim
if exists("g:loaded_nerdree_yank_filename_mapping")
finish
endif
let g:loaded_nerdree_yank_filename_mapping = 1
call NERDTreeAddKeyMap({
\ 'key': 'Y',
\ 'callback': 'NERDTreeYankFilename',
\ 'quickhelpText': 'Yank filename to unnamed register',
\ })
View test.vim
"
" Public interface, tweak as necessary
"
nnoremap <leader>f :echo <SID>FunctionName()<cr>
command! PrintFunctionName echo s:FunctionName()
"
" Implementation.
"
function! s:FunctionName()
View bookmarks.vim
" Ensure that the NERDTree is loaded before startify
runtime! plugin/nerdtree.vim
let g:startify_bookmarks = []
for bookmark in g:NERDTreeBookmarks
call add(g:startify_bookmarks, bookmark.path.str())
endfor
View rps_sinatra.rb
require 'sinatra'
get '/play/:choice' do
player_choice = params[:choice]
choices = ["rock", "paper", "scissors"]
if player_choice == "random"
player_choice = choices.sample
end
View rps_cli.rb
choices = ["rock", "paper", "scissors"]
puts "Enter one of: rock, paper, scissors"
print "> "
player_choice = gets.chomp
if not choices.include? player_choice
puts "Your choice, '#{player_choice}', is invalid"
exit
end
You can’t perform that action at this time.