Skip to content

Instantly share code, notes, and snippets.

View stevendaniels's full-sized avatar
👋

Steven Daniels stevendaniels

👋
View GitHub Profile
@stevendaniels
stevendaniels / extract_timestamp_from_hibernate_uuid.rb
Created April 25, 2014 08:57
Extract a timestamp from a UUID created by Hibernate's uuid.hex function.
def extract_timestamp_from_hibernate_uuid(str)
Time.at(str[16,12].to_i(16) / 1000)
end
@stevendaniels
stevendaniels / roo_quote_escaping_irb
Last active August 29, 2015 14:17
Roo .to_csv method
irb(main):001:0> require "roo"
true
irb(main):002:0> require "roo/version"
true
irb(main):003:0> Roo::VERSION
"2.0.0"
irb(main):004:0> filename = './quotes.ods'
irb(main):005:0> sheet = Roo::Spreadsheet.open(filename, extension: 'ods')
{[1, 1]=>"id", [1, 2]=>"quote", [2, 1]=>1.0, [2, 2]=>"\"Hello\"", [3, 1]=>2.0, [3, 2]=>"\"world\""}
irb(main):006:0> sheet.to_csv
@stevendaniels
stevendaniels / Gemfile
Created May 25, 2015 11:15
Sucker Punch Async Fails When Using Shotgun
source 'https://rubygems.org'
gem 'sucker_punch', '~> 1.5.0'
gem 'sinatra', '~> 1.4.6'
gem 'shotgun'
@stevendaniels
stevendaniels / Readme.md
Created July 4, 2015 23:00
Foreman export Port issue

Foreman's export sets the PORT env incorrectly when both the PORT is present in .env and concurrency > 1 is used in the export command.

foreman export -a bad_env -u me -e .env upstart . -c web=2

foreman export -a good_env -u me -e .env upstart . -c web=2 -t templates

@stevendaniels
stevendaniels / check-navigator-platform-benchmark.js
Created January 20, 2013 03:16
Is it faster to use regex to detect a browser's os, or indexOf?
//methodology: ran the test 4 times and took the slowest time.
checkOSRegex = function(){
var os = navigator.platform;
return /[wl]in/i.test(os) ? /win/i.test(os) ? 'linux' : 'windows' : 'mac'; //slightly confusing, but 26% faster than
}
checkOSRegexStart = Date.now();
for(var i = 0; i < 1000000; i++){
checkOSRegex('MacIntel');
@stevendaniels
stevendaniels / bm_dci_pounding.rb
Created March 30, 2016 11:32 — forked from raggi/bm_dci_pounding.rb
Show the effects of method cache damage from runtime extend, as it relates to extend vs. delegate for DCI.
require 'benchmark'
number_of_rails_methods = 300
@rails = Class.new do
number_of_rails_methods.times do |i|
class_eval <<-RUBY
def call#{"%02d" % i} # def call01
end # end
RUBY
@stevendaniels
stevendaniels / two_branch_cleanup_scripts.sh
Created August 22, 2016 20:37 — forked from Emuentes/two_branch_cleanup_scripts.sh
SCRIPT-ONE: will print the names of the branches that have been merged into develop AND master in green. Also, branches that are only merged into develop but not master are listed in red. ---- SCRIPT-TWO: will delete the fully merged branches, those listed in green when you run SCRIPT-ONE
#######################################
# SCRIPT 1 - PREVIEW BRANCH DELETIONS #
#######################################
# will print the names of the branches that have been merged into develop and master in green and branches that are only merged into develop but not master in red.
BRANCHES_IN_MASTER=`git branch -r --merged origin/master | grep -v -E '(\*|master$|develop$)' | cut -f2- -d '/' | tr '\n' ';'` && export BRANCHES_IN_MASTER && git branch -r --merged origin/develop | grep -v -E '(\*|master$|develop$)' | cut -f2- -d '/' | xargs -L1 bash -c 'if [ $(grep -o "$0" <<< "$BRANCHES_IN_MASTER" | wc -l) -gt 0 ] ; then printf "\e[0;32m $0 \e[0m\n"; else printf "\e[0;31m $0 is merged into DEVELOP but not MASTER \e[0m\n"; fi';
#################################################################################################################################
# SCRIPT 2 - DANGER -- RUN AT YOUR OWN RISK -- The following script will DELETE the branches listed in the above preview script #
###########################
@stevendaniels
stevendaniels / issue_344.rb
Last active December 28, 2016 15:08
Trying to duplicate Roo issue 344
require 'roo'
require 'roo/version'
puts Roo::VERSION
filename = "./test.xlsx"
file = File.open(filename)
spreadsheet = Roo::Spreadsheet.open(file, extension: :xlsx)
sheet_names = spreadsheet.sheets
sheet_names.each do |sheet_name|
@stevendaniels
stevendaniels / argb_to_rgba.rb
Last active July 14, 2017 04:36
ARGB to RGBA CSS Value
# https://en.wikipedia.org/wiki/RGBA_color_space#ARGB
def argb_to_rgba(argb)
argb.gsub(/(?<a>..)(?<r>..)(?<g>..)(?<b>..)/) do
matches = Regexp.last_match
"rgba(#{matches[:r].to_i(16)},#{matches[:g].to_i(16)},#{matches[:b].to_i(16)},#{matches[:a].to_i(16) / 255.0})"
end
end
# argb_to_rgba('FFFF0000')
# # => rgba(255, 0, 0, 1.0)
@stevendaniels
stevendaniels / 1
Last active August 14, 2017 12:40 — forked from mbostock/.block
Scatterplot
Scatterplot example