Skip to content

Instantly share code, notes, and snippets.

View runemadsen's full-sized avatar

Rune Skjoldborg Madsen runemadsen

View GitHub Profile
NYTD.NYTINT.AllStreams.Manager.parse({"hide":["something"],"show":["livestream","facebook"],"state":"stream"})
@runemadsen
runemadsen / couchdb.sh
Created September 16, 2011 22:36
CouchDB commands
/etc/init.d/couchdb start
@runemadsen
runemadsen / Maker Faire.txt
Created September 18, 2011 02:32
Maker Faire Presentation
Introduction
Why Processing?
Explain session
Go through process
Draw something
Save it to a photo
Open in photoshop and print
Shapes in Processing
@runemadsen
runemadsen / description.markdown
Created September 26, 2011 15:23
Reverse polymorphic associations in Rails

Polymorphic Associations reversed

It's pretty easy to do polymorphic associations in Rails: A Picture can belong to either a BlogPost or an Article. But what if you need the relationship the other way around? A Picture, a Text and a Video can belong to an Article, and that article can find all media by calling @article.media

This example shows how to create an ArticleElement join model that handles the polymorphic relationship. To add fields that are common to all polymorphic models, add fields to the join model.

///// Console
172-26-14-145:~ rune$ curl -X POST http://itp.ic.ht/public/_design/cakemix/_update/params?user=test&project=cats
[1] 2235
172-26-14-145:~ rune$ success: http://itp.ic.ht/public/cedc904e6fd323485575a4a6af00235f
///// Document
{
"_id": "cedc904e6fd323485575a4a6af00235f",
data.value.each do |row|
if row.hamster_count > 500
# use this row in data set
end
end
{
"from": "/user/:username",
"to": "/_view/users",
"query" : {
"reduce" : "false", "include_docs" : "true",
"startkey" : [":username", {}], "endkey" : [":username"],
"descending" : "true"
}
},
$.ajax({
type: "GET",
url: "http://www.itpcakemix.com/project/cats",
dataType: "jsonp",
success : function(data) {
alert(data);
}
});
// Java
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd'T'HH:mm:ss.S'Z'");
Date myDate = df.parse("2011-10-13T22:45:42.018Z");
println(myDate);
// Ruby
t = Time.parse("2011-10-13T22:45:42.018Z") + (60 * 60 * 4)
t = Time.parse("2011-10-13T22:45:42.018Z") + (60 * 60 * 4)