Skip to content

Instantly share code, notes, and snippets.

@emk
emk / form_steps.rb
Created April 29, 2009 23:08
Fill in multiline forms with Cucumber and Webrat
# Fill in multiple form fields using a table. Use it as follows:
#
# When I fill in the fields
# | Field 1 | Value 1 |
# | Field 2 | Value 2 |
When /^I fill in the fields$/ do |table|
table.rows_hash.each {|field, value| fill_in field, :with => value }
end
@emk
emk / parse.ex
Created August 13, 2013 02:01
Fun with Elixir bit bashing and weird Microsoft serialization formats
defmodule OcrMap.Parse do
use Bitwise, only_operators: true
def parse_7bit_encoded_int(rest) do
parse_7bit_encoded_int(rest, 0, 0)
end
def parse_7bit_encoded_int(<< 0::1, bits::7, rest::binary >>, shift, acc) do
{ (bits <<< shift) + acc, rest }
end
@emk
emk / ember-test.html
Created April 7, 2013 01:44
Testing Ember.js with Mocha, Sinon and Chai, including unit and integration tests. Runnable version available at: http://jsfiddle.net/ekidd/hCsws/13/
<!-- Mocha test output goes here. -->
<div id="mocha"></div>
<!-- Handlebars templates for our application. -->
<script type="text/x-handlebars">
<h1>Testing Ember.js with Mocha</h1>
{{outlet}}
</script>
<script type="text/x-handlebars" data-template-name="index">
@emk
emk / subjonctif.rb
Created February 22, 2013 15:01
French verbs with weird stems in the subjunctive, based on FrenchVerbWorkshop data.
# -*- coding: utf-8 -*-
require "rubygems"
require "bundler/setup"
require "nokogiri"
File.open('verbs-0-2-0.xml') do |f|
doc = Nokogiri::XML(f)
doc.css('Prototype').each do |p|
sprésent = p.attr('SPRÉSENT')
@emk
emk / Application.elm
Created December 1, 2015 13:06
Elm case matching on complex records?
type alias Model =
{ errorMessage: Maybe String -- This is what Rails would call a "flash": we just show it.
, video: Maybe Video.Model -- Information about a video and subtitles.
, player: Maybe VideoPlayer.Model -- Player state: URL, playing/paused, time.
}
type Action
= VideoLoaded Video.Model
| VideoPlayerAction VideoPlayer.Action
@emk
emk / htlal.user.js
Created September 26, 2012 17:49
HTLAL Fixups (userscript for Chrome)
// ==UserScript==
// @name HTLAL Fixups
// @description Make how-to-learn-any-language.com work a bit better.
// @match http://how-to-learn-any-language.com/*
// ==/UserScript==
// Fix word-wrap in textareas, so URLs don't get broken and posts don't get
// formatted strangely.
var textareas = document.getElementsByTagName("textarea");
for (var i = 0; i < textareas.length; i++) {
@emk
emk / 1_front.html
Created August 22, 2012 15:16
Anki 2 cards with hidden transliterations on the front
<div class="signes">{{Signes H}}</div>
<input type="button" value="Translittération" onclick="document.getElementById('transliteration').className += ' shown'; this.style.display = 'none'; return false;">
<div id="transliteration" class="transliteration">{{Translittération}}</div>
@emk
emk / etrais.rb
Created May 22, 2012 11:24
Une expérience : code source en français / An experiment: source code in French
# -*- coding: utf-8 -*-
# Ceci n'est pas une entrée. :-) Cette expression rationelle ( ou «
# regulière », si on préfère l'anglicisme ) correspond à quelques entrées
# fausses.
FAUSSES_ENTRÉES =
/^10 Natural|(13|19) Creating|15 Nouns|21 Adjectives|2[235] Verbs|24 Use|26 Adverbs/
# Valides parties du discours trouvées dans ce dictionnaire.
PARTIES_DU_DISCOURS = {}
@emk
emk / example.go
Created December 29, 2011 17:41
Pass by value/reference in Go, take 2
package main
// Holds any type of value.
var mixedSlice = make([]interface{}, 0)
// Holds only quaternions.
var quaternionSlice = make([]Quaternion, 0)
// A huge pass-by-value type: 256 bits wide.
type Quaternion struct {
@emk
emk / scratch.go
Created December 29, 2011 05:50
Pass by value/reference in Go
package scratch
type Foo struct {
}
func (f Foo) Frob() {
}
type Bar interface {
Frob()