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()
@hdeshev
hdeshev / .ctags
Created October 9, 2011 21:58
My Scala-enabled ctags config
--langdef=scala
--langmap=scala:.scala
--regex-scala=/^[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\1/c,classes/
--regex-scala=/.*class[ \t]+([a-zA-Z0-9_]+)/\1/c,classes/
--regex-scala=/^[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\1/t,traits/
--regex-scala=/.*trait[ \t]+([a-zA-Z0-9_]+)/\1/t,traits/
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t]*def[ \t]+([a-zA-Z0-9_\?]+)/\1/m,methods/
--regex-scala=/^[ \t]*val[ \t]+([a-zA-Z0-9_]+)/\1/C,constants/
--regex-scala=/^[ \t]*var[ \t]+([a-zA-Z0-9_]+)/\1/l,local variables/
@skanev
skanev / debug.rb
Created November 3, 2011 14:17
Debugging the performance of a Rails controller action
require 'rails/console/app'
ActiveSupport::Notifications.subscribe /^sql\./ do |*args|
puts caller.grep(%r[/garmz/]) { |line| " #{line.gsub(/.*?\/garmz\//, '')}" }.take(3) * "\n"
end
ActiveRecord::Base.logger = Logger.new(STDOUT)
app.get '/newsfeed'
ActiveRecord::Base.logger = Logger.new(nil)
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:29
Focus on specific specs in RSpec
# add this to your spec helper
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
# and then use the :focus tag in your specs
it "does something awesome", :focus do
@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
@AndrewRadev
AndrewRadev / nerdtree_fix.vim
Created November 11, 2011 18:28
When :edit-ing in NERDTree, open the file in the closest buffer instead
" 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!
#! /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!";;
@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

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

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

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

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

 first_registration = build(:registration, provider: 'twitter', uid: '123')