Skip to content

Instantly share code, notes, and snippets.

View lkosak's full-sized avatar

Lou Kosak lkosak

  • Airbnb
  • San Francisco, CA
View GitHub Profile
db.events.find({"name":"purchased_deal","is_first_time":{$exists:false}}).forEach(function(data) {
 var query = {
     "name" : data.name,
     "user_id" : data.user_id,
"date_created": { $lt : data.date_created }
   }
if(db.events.count(query) == 0) {
data.is_first_time = true
} else {
"pinch_cards": [
{
"qr_code":
-or-
"pinch_card_term_id":
-or-
"pinch_card_id":
"punch_count":
"punches": [
@lkosak
lkosak / gist:2353063
Created April 10, 2012 17:28 — forked from foxyblocks/gist:2314735
easy vim hash=>rocket and php $object->thingy
"Paste into your .vimrc
" for insert mode remap <c-l> to:
" Insert a hash rocket for ruby
" Insert a -> for php
function! SmartHash()
let ruby = &ft == 'ruby'
let php = &ft == 'php'
if php
@lkosak
lkosak / gist:2699716
Created May 15, 2012 07:15
Run them rails tests from vim!
function! RunRailsTest()
let file = expand("%")
let basepath = getcwd()
let in_test_file = match(file, '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if !in_test_file
" Come up with a best guess search path
let search_fname = fnamemodify(file, ":s?^app/??:s?.rb$?_spec.rb?")
" Search for that shit
redtail git:master ❯ rails s
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
=> Booting Thin
Installing nokogiri (1.5.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/lkosak/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
redtail git:master ❯ gem install nokogiri ⏎
Building native extensions. This could take a while...
Successfully installed nokogiri-1.5.5
1 gem installed
Installing ri documentation for nokogiri-1.5.5...
Installing RDoc documentation for nokogiri-1.5.5...
for i in {,{1..15}}; curl -s -w "%{time_total}\n" -o /dev/null http://127.0.0.1:3000/api/v1/markets/san-francisco/music\?limit\=50\&market\=san-francisco\&abc\=$i
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUNNING TESTS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <leader>t :call RunTestFile()<cr>
map <leader>rt :call RunNearestTest()<cr>
map <leader>. :call RunTests('')<cr>
map <leader>c :w\|:!cucumber %<cr>
map <leader>w :w\|:!script/acceptance --profile wip<cr>
function! RunTestFile(...)
times = []
for i in 1..15
res = `curl -s -w "%{time_connect}:%{time_starttransfer}\n" -o /dev/null http://www.pinchit.com/api/v1/markets/san-francisco/music\?limit\=50\&market\=san-francisco\&abc\=$i`
connect, transfer = res.strip.split(":").map { |t| t.to_f }
time = (transfer - connect).round(3)
times << time
puts time
end