Skip to content

Instantly share code, notes, and snippets.

@pachacamac
pachacamac / mrisc.rb
Created July 7, 2011 10:20
A Simple Assembler Language and VM
#!/usr/bin/env ruby
class MRISC
def run(code)
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';')
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact!
while @vars[:_pc] < tokens.size-1
@vars[:_pc] += 1
@vars[:_oc] += 1
@JakubOboza
JakubOboza / gist:1106325
Created July 26, 2011 09:00
Ruby Style Guide
Original Source: https://github.com/chneukirchen/styleguide
= Christian Neukirchen's Ruby Style Guide
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
@beastaugh
beastaugh / installing-ghc7.2-osx10.7.md
Created August 24, 2011 21:41
Installing GHC 7.2 on Mac OS X 10.7 Lion

Installing GHC 7.2 on Mac OS X

This is a brief and bare-bones guide to getting GHC 7.2 and the cabal-install tool (the two basic things you'll need to do Haskell development) up and running on a new Mac OS X 10.7 install.

The instructions given here worked for me, but YMMV.

#!/bin/bash
## MOVED TO https://github.com/sickill/git-dude
INTERVAL=30
ICON_PATH=`pwd`/icon.png
export LC_ALL=C # make sure git talks english
while [ 1 ]; do
for dir_name in *; do
@solnic
solnic / improved_dirty_tracking_in_dm_1.2.0.rb
Created October 13, 2011 11:25
improved_dirty_tracking_in_dm_1.2.0.rb
require 'rubygems'
require 'data_mapper'
DataMapper.setup :default, 'sqlite::memory:'
class Book
include DataMapper::Resource
property :id, Serial
property :meta, Json
@JakubOboza
JakubOboza / mongoid_tags.rb
Created November 22, 2011 15:04
tags formongoid collections.
module Mongoid
module Document
module Taggable
def self.included(base)
base.class_eval do |base_document|
base_document.field :tags, :type => Array, :default => []
base_document.index :tags
include InstanceMethods
extend ClassMethods
@bdha
bdha / vbox_to_kvm.txt
Created March 1, 2012 04:04
Migrating from VirtualBox to KVM on ZFS
# It's important to convert the vbox image (VMDK or VDI or whatever) using
# the same version of VirtualBox that created it. You can try converting the image
# with qemu-img or kvm-img, but weird version mismatches will possibly make it not
# work.
# On your VirtualBox machine:
cd $VBOX_ROOT/$MACHINE_ROOT/
VBoxManage clonehd machine.vmdk machine.img --format RAW
scp machine.img root@kvm-host:/somewhere
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@ku1ik
ku1ik / nginx.conf
Created April 25, 2012 19:24 — forked from lucasmazza/conf.md
Nginx upstart script that WORKS with Passenger.
description "nginx http daemon"
start on runlevel [2]
stop on runlevel [016]
console owner
exec /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf -g "daemon off;"
respawn
@jpayne
jpayne / Acknowledgement.txt
Created September 8, 2012 17:33
Start multiple Resque workers with Upstart
Thanks to Jason Roelofs for his article at http://jasonroelofs.com/2012/03/12/manage-and-monitor-resque-with-upstart-and-monit/ which got me most of the way there.