Skip to content

Instantly share code, notes, and snippets.

@abaldwin88
abaldwin88 / gist:5ee8677c2363d632c1f4a049642c7c4d
Created April 12, 2016 19:59 — forked from viola/gist:1070410
Example of fetching Hash (key,value) to the simple_form collection.
-- model
some sort of constant hash:
HASH_NAME = {
0 => "Choose:",
1 => "On-Campus Recruiting - CSO",·
2 => "CSO Staff Referral",
3 => "Faculty Contact",·
4 => "Career Day",·
5 => "CSO Summer Job Listing",·
6 => "Alumni Contact",·
@abaldwin88
abaldwin88 / fstash.zsh
Last active March 31, 2017 21:45 — forked from dekz/fstash.zsh
fzf + git stash
fstash() {
local out q k sha
while out=$(
git stash list --pretty="%C(yellow)%h %>(14)%Cgreen%cr %C(blue)%gs" |
fzf --ansi --no-sort --query="$q" --print-query \
--expect=ctrl-d,ctrl-b);
do
IFS=$'\n'; set -f
lines=($(<<< "$out"))
unset IFS; set +f
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
require 'httparty'
URL = 'http://localhost:3000/posts?search='
def get(search_term)
HTTParty.get(
"#{URL}#{search_term}"
)
end
require 'httparty'
URL = 'http://localhost:3000/posts?search='
def get(search_term)
HTTParty.get("#{URL}#{search_term}")
end
require 'benchmark'
def benchmark_get(search_term)
bm = Benchmark.realtime do
get(search_term)
end
bm * 1000
end
NUMBER_OF_TRIALS = 100
SEARCH_TERMS = ['scott', 'blake']
results = Hash.new { |h, k| h[k] = [] }
NUMBER_OF_TRIALS.times do |i|
SEARCH_TERMS.each do |term|
results[term] << benchmark_get(term)
end
end
NUMBER_OF_TRIALS = 100
DIGIT_LENGTH_RANGE = (10..70)
SEARCH_TERMS = DIGIT_LENGTH_RANGE.map do |i|
'?' * i
end
results = Hash.new { |h, k| h[k] = [] }
NUMBER_OF_TRIALS.times do |i|
SEARCH_TERMS.each do |term|
NUMBER_OF_TRIALS = 100
NUM_OF_CHARS = 43
CHAR_LIST = ('a'..'z').to_a
SEARCH_TERMS = CHAR_LIST.map do |letter|
letter + '?' * (NUM_OF_CHARS - 1)
end
results = Hash.new { |h, k| h[k] = [] }
NUMBER_OF_TRIALS.times do |i|