Skip to content

Instantly share code, notes, and snippets.

Chris Zetter zetter

Block or report user

Report or block zetter

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@zetter
zetter / tracepoint_log_process.rb
Created Mar 6, 2019
Code to process a log that I created using TracePoint
View tracepoint_log_process.rb
require 'json'
require 'csv'
class Line
attr_reader :thread_no, :line_no, :path, :klass, :method_id, :event, :code, :line
def initialize(row)
@thread_no, @line_no, @path, @klass, @method_id, @event, @code = row
end
@zetter
zetter / output.tsv
Last active Aug 17, 2018
Find words in Omegawiki that are the reverse of the same word in another language
View output.tsv
word_1 word_2 word_1_language word_2_language
ramer remar French Castilian
afaka akafa French Castilian
NATO OTAN English French
nier rein Afrikaans French
NATO OTAN German French
NATO OTAN Italian French
erum mure Ainu (Latin) Interlingua
NATO OTAN English Castilian
agua auga Castilian Mirandese
@zetter
zetter / wait_for_pending_requests.rb
Created Mar 22, 2018
Re-writing method without timeout
View wait_for_pending_requests.rb
def wait_for_pending_requests
start = Time.now
while pending_requests?
if (Time.now - start) > 60
raise "Requests did not finish in 60 seconds"
else
sleep(0.01)
end
end
@zetter
zetter / parse_icons_from_icomoon.rb
Created Dec 9, 2013
Parse the icon file from icomoon and print out a ruby hash of character names to characters.
View parse_icons_from_icomoon.rb
# Usage:
# run the file with the dev.svg from icomoon (not the plain svg)
# ruby parse_icons_from_icomoon.rb /path/to/iconfont.dev.svg
require 'nokogiri'
file = ARGV[0]
svg = File.open(file)
document = Nokogiri::XML(svg)
View subtyping.txt
There was a programmer from Skegness,
Who had a language that was a bit of a mess,
They implemented subtyping, and no longer was there griping,
All while keeping safety, preservation and progress
@zetter
zetter / Slow queries
Created Feb 8, 2011
Find the slowest queries lines in a rails development log
View Slow queries
file=''
slow = []
File.readlines(file).each do |line|
if line =~ /Load\ \(([\d\.]*)ms\)/
time = $1.to_f
if time >= 500.0
slow << [time, line]
end
end
@zetter
zetter / enrolment_cuke_spec.rb
Last active Jun 13, 2016
Enrolment cucumber-like rspec feature spec
View enrolment_cuke_spec.rb
feature 'Enrolment' do
scenario 'Enrolling in a course' do
given_there_is_a_course
and_i_am_logged_in_as_a_learner
when_i_enrol_on_a_course
then_the_course_should_appear_in_my_courses
end
def given_there_is_a_course
@course = FactoryGirl.create(:course)
@zetter
zetter / phantomjs
Last active Jan 3, 2016
Filter out userSpaceScaleFactor warning on phantomjs on Mavericks
View phantomjs
#!/bin/bash
/usr/local/bin/phantomjs_original $@ 2> >(grep -v userSpaceScaleFactor 1>&2)
@zetter
zetter / transaction_download.applescript
Last active Dec 27, 2015
Halifax Online Banking Transaction Downloader Applescript
View transaction_download.applescript
(*
Halifax Online Banking Transaction Downloader Applescript
https://gist.github.com/zetter/7387018
To use:
+ Set the path to an existing directory where you want to save the
pages.
+ Open Safari with a single window and tab and login to Halifax Online.
+ Load up the first page of the transactions for the account you want to save.
+ Run this script.
@zetter
zetter / find_git_remote_branches.sh
Created Oct 31, 2013
List the remote branches that with a last commit that you authored.
View find_git_remote_branches.sh
# list remote branches with committer name and email
function git_remote_branches_with_author {
for branch in `git branch -r | grep -v /HEAD`; do
echo -en "$branch ";
echo -e `git show -s --pretty=format:"%an %ae" $branch`;
done
}
# show filtered remote branches
function find_git_remote_branches {
You can’t perform that action at this time.