Skip to content

Instantly share code, notes, and snippets.

View emlyn's full-sized avatar

Emlyn Corrin emlyn

View GitHub Profile
@emlyn
emlyn / gbaltgr
Last active December 16, 2015 08:28
Custom keyboard layout: UK international with AltGr dead keys
partial alphanumeric_keys
xkb_symbols "altgr-gb" {
name[Group1]= "English (UK, international AltGr dead keys)";
include "latin"
key <TLDE> { [ grave, notsign, dead_grave, bar ] };
key <AE01> { [ 1, exclam, exclamdown, onesuperior ] };
key <AE02> { [ 2, quotedbl, dead_diaeresis, twosuperior ] };
@emlyn
emlyn / extract-text.clj
Last active December 18, 2015 12:28 — forked from jashmenn/extract-text.clj
Extract the text from a webpage using jericho html parser in clojure. Run with 'lein one-off extract-text.clj filename.html'
#_(defdeps [[net.htmlparser.jericho/jericho-html "3.1"]])
(ns foo.preprocess
(:import [java.io File BufferedInputStream FileInputStream]
[net.htmlparser.jericho Source TextExtractor HTMLElementName]))
(defn my-text-extractor [source]
(proxy [TextExtractor] [source]
(excludeElement [tag]
(= (.getName tag) HTMLElementName/PRE))))
@emlyn
emlyn / wikioccs2stanford.py
Last active December 19, 2015 02:38
Convert Wikipedia occurrences file generated by DBpedia Spotlight ExtractOccsFromWikipedia (& ExtractCandidateMap) to a format suitable for training Stanford NER (note: occurrences file must not be uri-sorted).
#!/usr/bin/env python
import argparse
from nltk.tokenize import wordpunct_tokenize
def split_parts(fulltext, entities):
text = fulltext
shift = 0
done = 0
parts = []
@emlyn
emlyn / hashtest.clj
Last active December 26, 2015 10:28
Clojure Hash Test
(def testset (for [a (range 20)
b (range 20)
c (range 20)
d (range 20)]
(conj #{[a b]} [c d])))
(def testvec (for [a (range 20)
b (range 20)
c (range 20)
d (range 20)]
[[a b] [c d]]))
@emlyn
emlyn / base64_fixedpoint.py
Last active February 24, 2023 22:32
Base64 Fixed Point Calculator in Python
#!/usr/bin/env python3
import sys
def get6bits(bytes, offset):
"Get 6-bit value from offset in bits in a string"
byte_offset = offset // 8
bit_offset = offset % 8
if bit_offset <= 2:
# The 6 bits of input are all in the same byte:
;; Doesn't work...
;; TODO: allow (truncate n (t/minutes 10)): "2014-06-27 12:34:56.789" -> "2014-06-27 12:30:00.000"
(defmacro mutator [method val]
`(fn [^MutableDateTime mdt#] (~method mdt# val)))
(defn truncate [^DateTime dt units]
(loop [^MutableDateTime mdt (.toMutableDateTime dt)
[[unit method] & more] [[t/years nil]
[t/months (mutator .setMonthOfYear 1)]
@emlyn
emlyn / emlyn.rb
Created July 1, 2015 23:13
From my first attempt at live coding, at the SwiftKey music night.
use_bpm 130
live_loop :tick do
root, type = [[:d4,:m7],[:g4,:dom7],[:c4,:M7],[:f4,:M7],[:b4,:'m7+5'],[:e4,:dom7],[:a4,:m7]].tick(:tick)
cue :boom, root: root, type: type
with_fx :reverb, amp: 2 do
sample :drum_cymbal_closed, amp: 3
sleep 0.5
3.times do
sample :drum_cymbal_closed
@emlyn
emlyn / dancing dream.rb
Last active February 15, 2018 09:16
Toby's Sonic Pi songs
use_bpm 120
use_synth :dsaw
p = [[:c4,:M7],[:a4,:m7],[:d4,:m7],[:g4,:dom7],[:e4,:m7],[:a4,:dom7],[:d4,:m7],[:g4,:dom7]]
in_thread do
sleep 8
12.times do
sample :loop_breakbeat, rate: sample_duration(:loop_breakbeat)/4
sleep 4
import os
try:
sc
except NameError:
from pyspark import SparkContext, SparkConf
sc = SparkContext(conf=SparkConf().setAppName("lol"))
dirs = ['/home/hadoop/.versions/spark-1.4.0.b/classpath/emrfs/',
'/home/hadoop/.versions/2.4.0-amzn-5/share/hadoop/common/lib/']
@emlyn
emlyn / innovation1.rb
Created October 9, 2015 11:50
Sonic Pi
use_bpm 180
use_random_seed 42
live_loop :drum do
a,b = [[:Ab,:major], [:F, :minor], [:C, :minor], [:G, :minor]].choose
cue :key, a: a, b: b
if true then
with_fx :reverb do
4.times do
sample :drum_tom_mid_hard, amp: ring(4,2,3,2).tick