Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View runemadsen's full-sized avatar

Rune Skjoldborg Madsen runemadsen

View GitHub Profile
@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.

@runemadsen
runemadsen / Thesis Essay
Created April 26, 2011 00:10
Thesis essay
1. Introduction
Since the birth of the software development discipline, programmers have dedicated time and effort into creating digital tools that optimize the process of going from an initial idea to a fully fledged product. This task is a hard one. How do you model a tool to support the non-linear, unstructured process of thinking? How do you create a tool that allows you to turn your thoughts into a digital document? A tool where you can build upon this document, iterate away on tangents when you get inspired, and quickly revert to a former state if this proved unsuccessful? More important, how do you create a tool that allows a group of people to collaborate on the same project, when that project doesn't have a structured form yet?
One answer to this question is the concept of a version control system, that today plays a central role in any serious software development project. It allows individuals to iterate code-based projects in a flexible environment, and to share these improvements with collabora
@runemadsen
runemadsen / Generator.java
Created February 7, 2012 23:01
How to create a .jar Processing app that you can launch from the command line
import processing.core.*;
public class Generator {
private PApplet applet = null;
private PGraphics context = null;
Generator()
{
@runemadsen
runemadsen / app.rb
Created October 17, 2012 13:45
Sinatra File Upload
require 'sinatra'
get "/" do
erb :form
end
post '/save_image' do
@filename = params[:file][:filename]
file = params[:file][:tempfile]
@runemadsen
runemadsen / logo.pde
Created August 20, 2021 15:55
The new Processing logo program
int u = 60;
boolean showGrid = true;
void setup() {
size(480, 480);
}
void draw() {
background(255);
if(showGrid) drawGrid();
Welcome (4:30 PM - 4:50 PM)
Workshops (5:00 PM - 6:20 PM)
Beginners Workshop: Getting Started with P5.js by Kristian Gårdhus Wichmann
Are you new to creative coding and programming? Fear not! This workshop will get you started immediately with the p5js library. Using the online editor, magic will happen in your browser in no time. Kristian spent his teenage years programming his Commodore 64. Later in life, while teaching secondary school, his interest in coding was rekindled by the youtube channel The Coding Train. Kristian currently works as a data scientist at Blackwood Seven.
Intermediate Workshop: Processing + Graphic Design = ❤️ by Stig Møller Hansen
var r = new Rune({
container: "#canvas",
width: 800,
height: 700,
debug: true
});
// Random
// ---------------------------------------
@runemadsen
runemadsen / How to import dump folder into mongodb.sh
Created March 7, 2011 19:35
This shows how to import the data from a dump folder produced by mongodump
# Make sure MongoDB is installed and working
# Start the mongodb server in terminal
sudo mongod
# In another terminal window, run mongorestore command (second option pointing to dump folder on your HD)
mongorestore -d version_05 Documents/dump
var r = new Rune({
container: "#canvas",
width: 800,
height: 600
});
function drawTriangle(x, y, s) {
r.triangle(x, y, x+(s/2), y+s, x-(s/2), y+s)
}
@runemadsen
runemadsen / handy.sh
Last active May 30, 2018 18:42
Handy Bash Scripts
# show top top 10 most consuming processes
ps -A --sort -rss -o comm,pmem,pcpu | head -n 11
# show total size of folder
du -ch | grep total
# show remaning space left on HD
df -h
# show subfolders of current dir and their size