Skip to content

Instantly share code, notes, and snippets.

View theawesomestllama's full-sized avatar

Patrick Koehn theawesomestllama

View GitHub Profile
@theawesomestllama
theawesomestllama / DataClass.ceylon
Created June 29, 2016 20:29
Attempt at a "data class" mixin in Ceylon.
import ceylon.language.meta {
type
}
import ceylon.language.meta.declaration {
ValueDeclaration
}
import ceylon.language.meta.model {
Attribute
}
@theawesomestllama
theawesomestllama / sonic_pi_patterned_progression.rb
Last active June 10, 2016 13:41
Simple Sonic Pi composition. Runs two patterns through a basic, randomized chord progression. https://soundcloud.com/forgottenflannelrepublic/in-the-shadows-of-moose-feet
# Welcome to Sonic Pi v2.9
Chord = Struct.new(:tonic, :scale, :degree, :duration)
def run_pattern(pattern, duration)
pattern.each do |b|
play yield if b == 1 or b == true
sleep (duration / pattern.length)
end
end
@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>
@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 / 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
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 / 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|
@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 / 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 / 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
#