Skip to content

Instantly share code, notes, and snippets.

@kennyp
kennyp / gist:5444483
Created April 23, 2013 15:21
Run concurrently with a progress bar.
def run_concurrently(title, jobs, &block)
mutex = Mutex.new
work = Queue.new
jobs.each {|j| work << j}
pbar = ProgressBar.create(title: title, total: jobs.length, format: '%a |%w>%i| %e %t')
threads = 4.times.map do
Thread.new do
loop do
block.call(work.pop(:nonblocking))
mutex.synchronize { pbar.increment }
@kennyp
kennyp / gist:5902608
Created July 1, 2013 17:00
Auto-complete for hcl.
_hcl () {
local cur prev opts cmds tasks
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="--help --version"
cmds="show tasks aliases set unset start stop resume note"
if [[ ${cur} == -* ]] ; then
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
class TrueClass
def to_i
1
end
end
class FalseClass
def to_i
0
end
@kennyp
kennyp / gist:6237628
Created August 15, 2013 02:09
LGTM button for pull requests.
// ==UserScript==
// @name LGTM Button
// @namespace lgtm.github.com
// @description Add a LGTM button to pull requests.
// @include https://github.com/Skookum/*/pull/*
// @version 1
// ==/UserScript==
var lgtmButton = document.createElement('button'),
buttonCont = document.querySelector('button[name="comment_and_close"]').parentNode,
commentBtn = buttonCont.querySelector('button:last-child');
@kennyp
kennyp / no_role.rb
Created March 10, 2014 15:07
Users without a role.
Spree::User.joins('LEFT JOIN "spree_roles_users" ON "spree_roles_users"."user_id" = "spree_users"."id" LEFT JOIN "spree_roles" ON "spree_roles"."id" = "spree_roles_users"."role_id"').group('spree_users.id').having('count(spree_roles.id) = 0')
function local_server() {
cp ~/lib/favicon.ico .
ruby -run -e httpd -- -b 127.0.0.1 -p 8080 . &> /dev/null &
local pid=$!
ngrok -subdomain=kennyp 8080
kill $!
rm favicon.ico
}
@kennyp
kennyp / .bashrc
Created July 3, 2014 15:49
Make love for bashrc.
_make () {
local curw=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=()
COMPREPLY=($(compgen -W "$(make -qp | grep : | grep '^[a-z]' | cut -d: -f1)" -- $curw))
return 0
}
complete -F _make make
" Notes {
" vim: set foldmarker={,} foldlevel=0 spell:
"
" Kenny Parnell <[email protected]>
" }
" General {
execute pathogen#infect()
set background=dark
set cmdheight=2
# Sinatra/Ruby
[~]» wrk -t 12 -c400 -d30s http://127.0.0.1:4567/test
Running 30s test @ http://127.0.0.1:4567/test
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 215.89ms 283.31ms 1.06s 80.72%
Req/Sec 259.81 272.75 1.21k 84.97%
44630 requests in 30.11s, 9.92MB read
Socket errors: connect 0, read 0, write 0, timeout 4110
Requests/sec: 1482.10
defmodule TestApp.PageController do
use Phoenix.Controller
plug :action
def test(conn, _params) do
conn |> text "OK"
end
end