Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Mock wavebeem

View GitHub Profile
View spin.py
#!/usr/bin/env python
import sys
import time
def uchar(code):
return ('\\U%08x' % code).decode('unicode-escape')
start = 0x1F550
end = 0x1F55B
emoji = map(uchar, range(start, end + 1))
View spin.rb
#!/usr/bin/env ruby
def spin
("\u{1F550}" .. "\u{1F55B}").cycle.each do |moji|
print moji, " "
sleep 0.1
print "\r"
end
end
View decorators.rb
module MyDecorators
def limit(max, name)
tries = 0
m = instance_method(name)
define_method(name) do |*args|
tries += 1
if tries <= max
m.bind(self).call(*args)
else
raise "LIMITER ENGAGED"
View backtracking.js
const P = require('parsimmon');
const Chalk = require('chalk');
function wants(x) {
process.stdout.write(Chalk.bold.red('( wants ' + Chalk.cyan(x) + ' ) '));
return x;
}
function got(x) {
console.log(Chalk.bold.green('( GOT ' + Chalk.cyan(x) + ' )'));
@wavebeem
wavebeem / fish_prompt.fish
Created Apr 30, 2016
Custom fish prompt of random emoji every time
View fish_prompt.fish
function fish_prompt
set E
set E $E \U1F51C # soon
set E $E \U1F354 # hamburger
set E $E \U1F4A9 # poo
set E $E \U1F47A # tengu
set E $E \U1F349 # watermelon
set E $E \U1F300 # cyclone
set E $E \U1F37A # beer
set E $E \U1F382 # cake
View math.js
var util = require("util");
var P = require("parsimmon");
// Throw away whitespace surrounding a string.
function operator(s) {
return P.optWhitespace
.then(P.string(s))
.skip(P.optWhitespace);
}
View functional-oop-mixins.js
function fly(creature) {
return (
"The " + creature.species +
" flies using its " + creature.methodOfFlight
);
}
function hunt(creature, otherCreature) {
return (
"The " + creature.species +
View bad.js
export default [
"module1",
"module2"
].map(x => System.import(x)).then(([
module1,
module2
])) => {
return {
myApi: whatever
};
View ew.coffee
setTimeout () ->
console.log("Hello!")
, 300
View ruby-ish.sqg.rb
### Imports
let {JSON, document, console} = global
### Basic data
let namedConstants = [true, false, null, undefined]
let numbers = [1, 2, 1_000, 3.14, NaN, -Infinity]
let strings = ["hello,\n", "\u{20}", "\"world\"\u{2757}"]
let arrays = [[], [1, 2], [3, [[4]], [5]]]