Skip to content

Instantly share code, notes, and snippets.

View theawesomestllama's full-sized avatar

Patrick Koehn theawesomestllama

View GitHub Profile
@theawesomestllama
theawesomestllama / property-descriptors.js
Created June 4, 2014 01:11
A simple extension of the Object class to simplify property descriptor manipulation.
"use strict";
/* Allows a nice way of manipulating property descriptors (e.g. making
* methods non-enumerable).
*
* Example:
*
* function TestClass() {};
* TestClass.prototype.testFunction = function () {console.log("Hello!")};
* TestClass.prototype.$("testFunction").setEnumerable(false);
@theawesomestllama
theawesomestllama / markdown.rb
Created June 4, 2014 07:04
Markdown -> HTML converter with support for headers and footers. Uses Redcarpet.
#!/usr/bin/env ruby
module TAL
module Markdown
require 'fileutils'
require 'optparse'
require 'pathname'
require 'redcarpet'
@theawesomestllama
theawesomestllama / versionable.rb
Created June 25, 2014 06:53
Basic object versioning. Based on Aversion module by txus. Second version here: https://gist.github.com/theawesomestllama/daaed517c6d915bd6936
# Based on Aversion module by txus
# https://github.com/txus/aversion
#
# Example:
#
# class VersionableTest
# include Versionable
#
# versioned_accessor :cheese
#
@theawesomestllama
theawesomestllama / versionable.rb
Last active August 29, 2015 14:03
Second version of basic object versioning. Loses immutability. Gains string & array based history (no stored procs). Maybe faster? First version here: https://gist.github.com/theawesomestllama/44f6356874b0957d02c2
# Example:
#
# class VersionableTest
# include Versionable
#
# versioned_accessor :cheese, :mustard
#
# def initialize(val)
# @cheese = val
# @mustard = nil
@theawesomestllama
theawesomestllama / generate_mac_address.rb
Created July 29, 2014 19:44
Generates a random MAC address with support for OUI.
#!/usr/bin/env ruby
require 'optparse'
def run!
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
opts.on('-a', '--assignee ASSIGNEE', 'IEEE Assignee') do |assignee|
@theawesomestllama
theawesomestllama / game.rb
Created November 28, 2014 23:51
Stage one of version 0.0.0.1 of some kind of potential future Ruby/JavaScript+three.js game thing.
require 'json'
module Observable
def self.included(mod)
class << mod
attr_reader :__metadata__
end
mod.class_eval do
self.define_singleton_method(:observed_writer) do |*names|
names.each do |name|
Object.prototype.descriptor = function (property) {
"use strict";
var self = this;
var property_descriptor;
var refresh_descriptor = function () {
"use strict";
property_descriptor = Object.getOwnPropertyDescriptor(self, property) || {
enumerable: true,
configurable: true,
@theawesomestllama
theawesomestllama / graph.ml
Last active August 29, 2015 14:25
SUPER basic graph/network implementation to try out OCaml.
open Core.Std
module type G = sig
type node_data
type edge_data
module rec Node : sig
type t with sexp
val compare : t -> t -> int
@theawesomestllama
theawesomestllama / EchoSocket.fsx
Last active August 29, 2015 14:27
Messing around in FSI.
let manage_socket (socket : System.Net.WebSockets.WebSocket) =
async {
printfn "Managing socket."
let! token = Async.CancellationToken
let buffer = System.Net.WebSockets.WebSocket.CreateServerBuffer(2048)
let rec loop cont =
if cont then
let break_on_exception thunk =
try
thunk()
@theawesomestllama
theawesomestllama / TreeOfSeventeen.fs
Created April 30, 2016 09:50
Not quite golf. CodeFights solution.
type NodeID = int
type EdgeData =
| AddEdge of int
| SetEdge of int
type Edge = NodeID * NodeID * EdgeData
type Tree = Map<NodeID, Edge list>