Skip to content

Instantly share code, notes, and snippets.

Avatar
👋

Steven Daniels stevendaniels

👋
View GitHub Profile
@stevendaniels
stevendaniels / 1
Last active Aug 14, 2017 — forked from mbostock/.block
Scatterplot
View 1
Scatterplot example
@stevendaniels
stevendaniels / issue_344.rb
Last active Dec 28, 2016
Trying to duplicate Roo issue 344
View issue_344.rb
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 / two_branch_cleanup_scripts.sh
Created Aug 22, 2016 — 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
View two_branch_cleanup_scripts.sh
#######################################
# 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 / bm_dci_pounding.rb
Created Mar 30, 2016 — 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.
View bm_dci_pounding.rb
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 / Readme.md
Created Jul 4, 2015
Foreman export Port issue
View Readme.md

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 / Gemfile
Created May 25, 2015
Sucker Punch Async Fails When Using Shotgun
View Gemfile
source 'https://rubygems.org'
gem 'sucker_punch', '~> 1.5.0'
gem 'sinatra', '~> 1.4.6'
gem 'shotgun'
@stevendaniels
stevendaniels / argb_to_rgba.rb
Last active Jul 14, 2017
ARGB to RGBA CSS Value
View argb_to_rgba.rb
# 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)
View roo_quote_escaping_irb
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 / roo_error.irb
Last active Dec 11, 2017 — forked from reshleman/irb
Roo Bug Report
View roo_error.irb
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> sheet = Roo::Spreadsheet.open("/Users/reshleman/Desktop/roo_error.xlsx", extension: "xlsx")
=> {[1, 1]=>#<Roo::Excelx::Cell:0x007fe6b297fef0 @type=:string, @formula=nil, @excelx_type=:string, @excelx_value="0", @style=0, @value="name", @coordinate=#<Roo::Excelx::Cell::Coordinate:0x007fe6b297ff40 @row=1, @column=1>>, [2, 1]=>#<Roo::Excelx::Cell:0x007fe6b297f798 @type=:string, @formula=nil, @excelx_type=:string, @excelx_value="1", @style=0, @value="Robert Eshleman", @coordinate=#<Roo::Excelx::Cell::Coordinate:0x007fe6b297f7e8 @row=2, @column=1>>}
irb(main):005:0> sheet.parse(name: "name")
=> [{:name=>"name"}, {:name=>"Robert Eshleman"}]
@stevendaniels
stevendaniels / extract_timestamp_from_hibernate_uuid.rb
Created Apr 25, 2014
Extract a timestamp from a UUID created by Hibernate's uuid.hex function.
View extract_timestamp_from_hibernate_uuid.rb
def extract_timestamp_from_hibernate_uuid(str)
Time.at(str[16,12].to_i(16) / 1000)
end