Да разгледаме този код:
describe Registration do
it "disallows duplicates" do
create(:registration, uid: '123', provider: 'twitter')
first_registration = build(:registration, provider: 'twitter', uid: '123')
" Whenever you execute an `:edit somefile` command with the cursor in the | |
" NERDTree, the file gets edited in the NERDTree buffer, which is usually not | |
" something you want. This autocommand attempts to edit the given file in the | |
" closest non-NERDTree buffer instead. | |
" | |
" It's fairly hacky, but seems to work. I'll probably use it myself, so I'll | |
" try to remember to update it if I find any problems. | |
augroup AvoidEditingNERDTree | |
autocmd! |
# 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 |
let s:undo_stack = [] | |
command! -nargs=1 With call s:With(<f-args>) | |
function! s:With(expression) | |
if a:expression[0] == '*' | |
return s:WithFunction(a:expression) | |
else | |
return s:WithVariable(a:expression) | |
endif | |
endfunction |
$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 +@ |
#! /usr/bin/env ruby | |
require 'tempfile' | |
require 'vimrunner' | |
require 'nokogiri' | |
require 'json' | |
if ARGV.count < 2 | |
puts "USAGE: tohtml <colorscheme-file> <filename> [filenames ...]" | |
exit 1 |
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')", | |
\ } | |
\ ] |
#! /bin/sh | |
# If you often mistype "git add", you could alias "ad=add". Or, you could use | |
# this script. | |
random=$(( RANDOM % 3 )); | |
case $random in | |
0) echo "Buy Git! Now with 20% more rebase!";; | |
1) echo "Merge, branch, AND rebase? But wait, there's more!";; |
How I would describe quicksort in an imperative way:
def sort(list):
pivot is midpoint(list)
left_part is an empty list
right_part is an empty list
for every item in the list
if the item is smaller than the pivot
add(item) to left_part
# 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" |