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
@searls
searls / market_research.rb
Last active Sep 18, 2018
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)
View market_research.rb
# 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"
View computation.md

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
View git-ad
#! /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!";;
View alignment.md

Относно подравняването на кода.

Да разгледаме този код:

describe Registration do
  it "disallows duplicates" do
    create(:registration, uid: '123', provider: 'twitter')

    first_registration  = build(:registration, provider: 'twitter',  uid: '123')
@othree
othree / switchCase.vim
Created May 27, 2013
Switch between different case type: camelCase -> MixedCase -> snake_case -> UPPER_CASE -> dash-case -> camelCase
View switchCase.vim
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')",
\ }
\ ]
@AndrewRadev
AndrewRadev / tohtml
Last active Aug 13, 2016
Use Vim's :TOhtml to make the core of a syntax highlighter.
View tohtml
#! /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
@andkerosine
andkerosine / raskell.rb
Created Aug 15, 2012
Haskell-like list comprehensions in Ruby
View raskell.rb
$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 +@
@AndrewRadev
AndrewRadev / with.vim
Created Apr 16, 2012
"with" command for vimscript
View with.vim
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
@skanev
skanev / autocomplete_from_tmux.sh
Created Feb 1, 2012
zsh: autocomplete words in current tmux session
View autocomplete_from_tmux.sh
# 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
@AndrewRadev
AndrewRadev / nerdtree_fix.vim
Created Nov 11, 2011
When :edit-ing in NERDTree, open the file in the closest buffer instead
View nerdtree_fix.vim
" 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!
You can’t perform that action at this time.