Skip to content

Instantly share code, notes, and snippets.

View tosbourn's full-sized avatar
🏠
Working from home

Toby Osbourn tosbourn

🏠
Working from home
View GitHub Profile
[
{
"code": "AF",
"name": "Afghanistan"
},
{
"code": "AX",
"name": "Aland Islands"
},
{
@albertstill
albertstill / enigma_machine.rb
Last active February 25, 2021 18:46
Understand how the Enigma machine works with 30 lines of Ruby
Plugboard = Hash[*('A'..'Z').to_a.sample(20)]
Plugboard.merge!(Plugboard.invert)
Plugboard.default_proc = proc { |_, key| key }
def build_a_rotor
Hash[('A'..'Z').zip(('A'..'Z').to_a.shuffle)]
end
ROTOR_1, ROTOR_2, ROTOR_3 = build_a_rotor, build_a_rotor, build_a_rotor
@derekjohnson
derekjohnson / resize-monitor.js
Last active December 14, 2015 05:38
Small snippet to log an event in Google Analytics when a browser window is resized. It's often assumed designers and developers are the only people who resize the browser to see responsive web design in action. Let's test that assumption.
if(window.addEventListener) { // correlates with media query support
var timer = false
, resize_monitor = function() {
if(timer) {
clearTimeout(timer);
}
timer = setTimeout(function() { _gaq.push(['_trackEvent', 'Resize', 'Resize', 'Resized']); }, 100);
// or log a pageview on a non-existant page if you prefer
@xdissent
xdissent / gist:2860403
Created June 2, 2012 23:02
Ember-data hasMany computed properties test
test("filtered property on hasMany assoctiation", function() {
var File = DS.Model.extend({
primaryKey: 'name',
name: DS.attr('string'),
status: DS.attr('string')
});
var Project = DS.Model.extend({
primaryKey: 'name',