Skip to content

Instantly share code, notes, and snippets.

@zetter
zetter / cache_recipies.rb
Created Dec 27, 2020
Script for caching external links from a jekyll site.
View cache_recipies.rb
require "jekyll"
require "ostruct"
require "faraday"
def data_for_file(path)
content = File.read(path)
if content =~ Jekyll::Document::YAML_FRONT_MATTER_REGEXP
content = $POSTMATCH
data = SafeYAML.load(Regexp.last_match(1))
return data
View cheese-and-marmite-flapjacks.md
layout title from link quote type
cookbook
Cheese and marmite flapjacks
Sarah Cook (Olive)
A great way to pack in the oats without adding tons of sugar – these savoury flapjacks combine cheese and Marmite together for an umami flavour explosion.
savoury

I was looking for a savoury recipe to use up some oats. Once I was out of marmite and used white miso paste instead.

@zetter
zetter / enrolment_cuke_spec.rb
Last active Jun 28, 2020
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 / 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 / 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)