Skip to content

Instantly share code, notes, and snippets.

@epitron
epitron / bits.coffee
Last active August 29, 2015 14:08
Monkeypatching base JavaScript types (Array, Number) using CoffeeScript!
Number::log = (base)-> Math.log(this)/Math.log(base)
Number::pow = (exp)-> Math.pow(this, exp)
Number::ceil = -> Math.ceil(this)
Number::floor = -> Math.floor(this)
Array::first = -> this[0]
Array::last = -> this[@length-1]
Array::min = -> @sort().first()
Array::max = -> @sort().last()
Array::minmax = -> sorted = @sort(); [sorted.first(), sorted.last()]
@epitron
epitron / array_tweaks.coffee
Last active August 29, 2015 14:10
Extending JavaScript's Array object in CoffeeScript
class Array
all: (f)->
for e in this
return false unless f(e)
true
any: (f)->
for e in this
return true if f(e)
false
@epitron
epitron / lugcast.js
Last active July 3, 2016 18:18
An audio player I wrote for the SteamLUG Podcast (https://steamlug.org/cast). It highlights the transcript as the audio is playing, and lets you jump around in the audio by clicking the transcript.
(function () {
"use strict";
function time_to_seconds(time) {
var s = time.attributes.datetime.value.split(":");
return parseInt(s[0] * 3600, 10) + parseInt(s[1] * 60, 10) + parseInt(s[2], 10);
}
var highlighter = {
$ Number.prototype.divmod = function (n) { return [Math.floor(this / n), this % n]; }
=> function (n) {
return [Math.floor(this / n), this % n];
}
$ typeof 1
=> "number"
$ typeof 1.0
=> "number"
$ 1.0.divmod
=> embedded:16 function (n) {
@epitron
epitron / downto.c
Created December 1, 2014 04:34
A C "downto" operator, made of regular C syntax.
#include <stdio.h>
int main() {
int x = 10;
while (x --> 0) { // x downto 0
printf("%d ", x);
}
}
@epitron
epitron / -
Created December 3, 2014 07:16
$ grep -i conlang *lesswrong*|field 3|sort|uniq -c
4 *
1 Betawolf
1 c0rw1n
3 capisce
1 cardboard_box
1 catern
1 cntarantula
1 cntgrational
1 cntnamstyle
@epitron
epitron / crazytemplate.rb
Created December 4, 2014 04:59
Crazy Ruby Templating System, using Regular Ruby Strings!
require 'binding_of_caller'
class Tmpl
def initialize(&block)
@tmpl = block
end
def render
@thebinding = binding.of_caller(1)
@epitron
epitron / page
Created December 12, 2014 08:16
#!/usr/bin/env ruby
require 'io/console'
thread = Thread.new do
$stdin.each_line do |line|
print "stdin: #{line}\r"
end
end
#!/usr/bin/env ruby
require 'epitools'
class Array
def without(letters)
grouped = group_by { |letter| letter }
letters.each do |letter|
@epitron
epitron / gui-binding-stats.txt
Last active August 29, 2015 14:11
GUI bindings require a ridiculous amount of code. (Ranging from 19,000-200,000 lines.)
### wxruby #########################
1500 text files.
1480 unique files.
813 files ignored.
http://cloc.sourceforge.net v 1.60 T=4.21 s (172.6 files/s, 16513.3 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------