Skip to content

Instantly share code, notes, and snippets.

@jgaskins
jgaskins / no_nil_set.rb
Created November 26, 2013 00:59
A Set class that rejects nil
require 'set'
class NoNilSet
include Enumerable
def initialize(values=[])
@set = Set.new
@set += Array(values).compact
end
@jc00ke
jc00ke / uuid.rb
Created December 27, 2013 07:27
Rust/Ruby FFI
require 'ffi'
module Rust
module Uuid
extend FFI::Library
ffi_lib './librust_uuid-2b1863329f7b31d9-0.1.so'
attach_function :asdf, [], :string
attach_function :uuid_str, [], :void
end
@jc00ke
jc00ke / copy.sql
Created January 8, 2014 19:07
psql \copy csv
\copy (
select
name,
unit_price
from
widgets
) to 'widgets.csv' with (FORMAT CSV, force_quote *, header);
@jc00ke
jc00ke / query-with-pgtz.sql
Last active January 2, 2016 16:09
psql timezones
-- $> PGTZ=PST8PDT psql
-- If the PGTZ environment variable is set in the frontend environment
-- of a client based on libpq, libpq will automatically SET TIMEZONE to
-- the value of PGTZ during connection start-up.
select
created_at,
created_at at time zone 'UTC' at_tz_utc,
created_at at time zone 'PST' at_tz_pst,
created_at at time zone 'PST' - interval '8 hours' at_tz_pst_minus_8_hours
@jc00ke
jc00ke / awk.sh
Last active January 3, 2016 12:49
Awks
$> ag FOO some_file | awk 'split($0, a, "\"") { print $2, $3 }'
FOO_WIDGET_COUNT=1
FOO_WIDGET_NAME="Black Jack Johnson"
@mattvv
mattvv / credit_card_helper.rb
Created March 17, 2014 19:15
Include this in your test_helper.rb to stub your stripe checkout.js
#this is a very simple, work in progress helper method for stubbing the stripe checkout.js
#this creates a fake server that will generate stripe token as if it's coming from stripe. So we can test credit card input
class FakeStripe < Sinatra::Base
def self.boot
instance = new
Capybara::Server.new(instance).tap { |server| server.boot }
end
get '/checkout.js' do
@jodosha
jodosha / Gemfile
Last active December 9, 2020 15:09
Full stack Lotus application example
source 'https://rubygems.org'
gem 'rake'
gem 'lotus-router'
gem 'lotus-controller'
gem 'lotus-view'
group :test do
gem 'rspec'
gem 'capybara'
This tool is used to compare microbenchmarks across two versions of code. It's
paranoid about nulling out timing error, so the numbers should be meaningful.
It runs the benchmarks many times, scaling the iterations up if the benchmark
is extremely short, and it nulls out its own timing overhead while doing so. It
reports results graphically with a text interface in the terminal.
You first run it with --record, which generates a JSON dotfile with runtimes
for each of your benchmarks. Then you change the code and run again with
--compare, which re-runs and generates comparison plots between your recorded
and current times. In the example output, I did a --record on the master
#compdef tmuxinator mux
# zsh completion for tmuxinator
# Install:
# $ mkdir -p ~/.tmuxinator/completion
# $ cp _tmuxinator ~/.tmuxinator/completion
# $ vi ~/.zshrc # add the following codes
# fpath=($HOME/.tmuxinator/completion ${fpath})
# autoload -U compinit
#!/bin/sh
# Cisco Anyconnect CSD wrapper for OpenConnect
CSTUB="$HOME/.cisco/hostscan/bin/cstub"
$ARCH=$(uname -m)
if [[ "$ARCH" == "x86_64" ]]
then