Skip to content

Instantly share code, notes, and snippets.

@emk
emk / gist:fd4847bb732ebbd7d5e7
Created July 13, 2014 12:02
Iron middleware with unhandled request returns 200 OK
Escape character is '^]'.
GET /foo.txt HTTP/1.1
Host: www.example.com
HTTP/1.1 200 OK
Transfer-Encoding: chunked
0
@emk
emk / gist:1edb38d29b5078091e1b
Created July 12, 2014 21:23
Cargo failing on Heroku
Updating git repository `https://github.com/iron/iron.git`
fatal: Not a git repository: '.'
Unable to update https://github.com/iron/iron.git
Caused by:
Unable to update https://github.com/iron/iron.git
Caused by:
Executing `git fetch --force --quiet origin` failed
@emk
emk / french-blogs.opml
Created June 8, 2014 12:58
French-language blogs
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>French blogs</title>
</head>
<body>
<outline text="Actualitiés" title="Actualitiés">
<outline type="rss" text="Le Monde.fr - Actualité à la Une" title="Le Monde.fr - Actualité à la Une" xmlUrl="http://www.lemonde.fr/rss/sequence/0,2-3208,1-0,0.xml" htmlUrl="http://www.lemonde.fr/rss/une.xml"/>
<outline type="rss" text="LE FIGARO - Le Figaro - Actualité en direct et informations en continu" title="LE FIGARO - Le Figaro - Actualité en direct et informations en continu" xmlUrl="http://www.lefigaro.fr/rss/figaro_une.xml" htmlUrl="http://www.lefigaro.fr/"/>
@emk
emk / try_opt.rs
Created June 2, 2014 10:23
try_opt!
macro_rules! try_opt(
($e:expr) => (match $e { Some(v) => v, None => return None });
)
@emk
emk / collect_example.rs
Created June 1, 2014 17:33
Rust: Using 'collect' after we map something which might fail
impl FromStr for LanguageTag {
fn from_str(s: &str) -> Option<LanguageTag> {
fn parse(s: &str) -> Option<Tag> { from_str(s) }
let parsed: Option<Vec<Tag>> = collect(s.split('-').map(parse));
match parsed {
Some(components) => Some(LanguageTag { components: components }),
None => None
}
}
}
@emk
emk / gist:9f27145d7f2e593d1463
Last active August 29, 2015 14:02
Rust dynamic linked on Heroku
$ heroku run ldd ./lang-detect
Running `ldd ./lang-detect` attached to terminal... up, run.9621
linux-vdso.so.1 => (0x00007fff82163000)
librustful-9550c8e3-0.1-pre.so => /app/./lib/rustful/lib/librustful-9550c8e3-0.1-pre.so (0x00007f67ee595000)
libnative-1fb5e2c0-0.11.0-pre.so => not found
libhttp-2cee9fa1-0.1-pre.so => /app/./lib/rustful/lib/libhttp-2cee9fa1-0.1-pre.so (0x00007f67ee283000)
libcollections-d412c0c4-0.11.0-pre.so => not found
librand-2ea8f361-0.11.0-pre.so => not found
libstd-59beb4f7-0.11.0-pre.so => not found
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f67ee06b000)
@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 / 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++) {