Skip to content

Instantly share code, notes, and snippets.

View drernie's full-sized avatar

Dr. Ernie Prabhakar drernie

View GitHub Profile
@drernie
drernie / csvtomap.go
Created March 10, 2017 22:48
Golang Convert CSV Records to Dictionaries using Header Row as Keys
// CSVToMap takes a reader and returns an array of dictionaries, using the header row as the keys
func CSVToMap(reader io.Reader) []map[string]string {
r := csv.NewReader(reader)
rows := []map[string]string{}
var header []string
for {
record, err := r.Read()
if err == io.EOF {
break
}
@drernie
drernie / rxv.coffee
Last active August 29, 2015 14:07 — forked from eizenberg/rxv
A reactive SVG implementation for reactive-coffee by @yang (originally by @eizenberg)
# As used in http://jsfiddle.net/DrErnie/p09bjgh3/
# Preamble - may need to be in User Code
_.mixin(_.str.exports())
bind = rx.bind
rxt.importTags()
# Create rxv Versions
@drernie
drernie / theory_of_programming.md
Last active August 29, 2015 14:06
Towards a Scientific Theory of Programming

Proposed Components for a Simple, Scientific Theory of Programming

Draft 3

cc: @jonathoda @jamiiecb @jeresig @twleung @lindsey @a_cowley @kmett @ezyang @lambda_calculus

Inspired by The Future Programming Manifesto

Premise

(function() {
// Do not use this library. This is just a fun example to prove a
// point.
var Bloop = window.Bloop = {};
var mountId = 0;
function newMountId() {
return mountId++;
}

Introduction

SimpleMarkup parses plain text documents and attempts to decompose them into their constituent parts. Some of these parts are high-level: paragraphs, chunks of verbatim text, list entries and the like. Other parts happen at the character level: a piece of bold text, a word in code font. This markup is similar in spirit to that used on WikiWiki webs, where folks create web pages using a simple set of formatting rules.

require 'dispatch'
T=1
T0 = Time.now
def now
(Time.now - T0)
end
p "Call Dispatch.sync with delay #{T} @ #{now}"
Dispatch.sync {sleep T; p "Waited for me"}
p "Finished calling sync @ #{now}"
module Dispatch
class Actor
# Create an Actor that serializes or asynchronizes the given object
# Will invoke and call-back asynchronously if provide a block
# Note that this will NOT work for methods that themselves expect a block
def initialize(actee, callback=nil)
@actee = actee
@callback = callback || Dispatch::Queue.concurrent
@q = Dispatch::Queue.new("dispatch.actor.#{actee}.#{object_id}")
end
module Dispatch
# Wrapper around Dispatch::Group used to implement lazy Futures
class Future
# Create a future that asynchronously dispatches the block
# to a concurrent queue of the specified (optional) +priority+
def initialize(priority=nil, &block)
@group = Group.new
@value = nil
Dispatch::Queue.concurrent(priority).async(@group) { @value = block.call }
@drernie
drernie / mqparse.rb
Created August 22, 2008 22:21
Parse CSS 3 Media Queries
#!/usr/bin/env ruby
#
# mqparse - Media Query parser
# Copyright 2008 Apple, Inc. All Rights Reserved.
# http://gist.github.com/6863
#
# cf. http://www.w3.org/TR/css3-mediaqueries
require 'pp'
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:ac="http://purl.org/podcast/atomcast"
xml:base="http://www.example.com"
xml:lang="en-us">
<id>http://example.com/myfeed.atom</id>
<updated>2008-06-05T14:39:57-08:00</updated>
<title type="text">All About Everything</title>
<subtitle type="html">A show about &lt;em&gt;everything&lt;/em&gt;</subtitle>
<ac:summary type="xhtml">