Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@benoittgt
benoittgt / file.vim
Last active April 6, 2024 10:28
iamaputsemojidebugger
function! IAmAPutsEmojiDebugger()
ruby <<EOS
separator = rand(0x1F601..0x1F64F).chr('UTF-8')
VIM::command("normal! oputs '#{separator}' * (`tput cols`.to_i / 2)")
VIM::command('normal! oputs "#{__FILE__}:#{__LINE__}"')
VIM::command("normal! oputs '#{separator}' * (`tput cols`.to_i / 2)")
EOS
@searls
searls / market_research.rb
Last active September 18, 2018 03:21
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)
# 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"

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

#! /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!";;

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

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

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 07:08
Switch between different case type: camelCase -> MixedCase -> snake_case -> UPPER_CASE -> dash-case -> camelCase
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 August 13, 2016 13:57
Use Vim's :TOhtml to make the core of a syntax highlighter.
#! /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 August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$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 April 16, 2012 11:44
"with" command for vimscript
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 February 1, 2012 09:41
zsh: autocomplete words in current tmux session
# 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