Skip to content

Instantly share code, notes, and snippets.


Jussi Räsänen jrasanen

View GitHub Profile
madwork / attachment.rb
Last active Jul 25, 2021
Polymorphic attachments with CarrierWave and nested_attributes
View attachment.rb
class Attachment < ActiveRecord::Base
mount_uploader :attachment, AttachmentUploader
# Associations
belongs_to :attached_item, polymorphic: true
# Validations
validates_presence_of :attachment
ChuckJHardy / run.js
Created Sep 28, 2013
Express Server for ZeroMQ, and Angular.js
View run.js
'use strict';
var express = require('express'),
app = express(),
http = require('http'),
server = http.createServer(app),
path = require('path'),
io = require('').listen(server),
fs = require('fs'),
zmq = require('zmq'),
nnarhinen / index.html
Created Aug 9, 2013
POST Form to new window and wait for postMessage
View index.html
<title>Post form in a new window without losing handle to the window</title>
<script src=""></script>
$(function() {
$('form').on('submit', function(ev) {
var form = $(this);
form.attr('target', 'new-window');
if [ -f /usr/local/bin/virtualenv ];
virtualenv --no-site-packages --distribute -- $1
elif [ -f /usr/bin/virtualenv ];
virtualenv --no-site-packages --distribute -- $1
echo "No virtualenv found. Please install setuptools & virtualenv. :("
kgrz / mongoid3_sinatra_config.rb
Created Aug 22, 2012
A Better Mongoid Sinatra configuration implementation. Using settings hash for db options sucks!
View mongoid3_sinatra_config.rb
# This is a modification of the blogpost on how to use Mongoid and Sinatra.
# Here is the original blogpost
# The modification lets you use Mongoid 3.0 with the new Moped driver
# The new Moped driver uses the Sessions component to define the MongoDB connection rather
# than the that is used in the case of the default Ruby driver.
# vs
# Mongoid.load!(yaml_config.yml) is used to build the config hash. Alternatively, the hash can
# be built manually by using Mongoid.config {|config| ...} syntax. The config.sessions hash
randrews / main.lua
Created Aug 8, 2012
Example code for nice-feeling player movement in Love
View main.lua
require 'point'
function love.load()
love.physics.setMeter(32), 120, 64)
world = love.physics.newWorld(0, 0)
crates = { makeCrate(world, 5, 5),
makeCrate(world, 5, 6) }