Skip to content

Instantly share code, notes, and snippets.

@borgand
borgand / Controller.php
Created April 9, 2013 22:04
Add this to your protected/components/Controller.php class to allow mixed cache keys in Yii: $this->beginCache($product)
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class Controller extends CController
{
// Rest of the Controller class
@borgand
borgand / sequence_helper.rb
Created November 14, 2012 14:05
PosgtgreSQL sequence helper for ActiveRecord
# Helper for PostgreSQL Sequences
# USAGE:
# SequenceHelper.nextval('somenumber_seq')
# SequenceHelper.currval('somenumber_seq')
# SequenceHelper.reset('somenumber_seq', 10)
class SequenceHelper < ActiveRecord::Base
# Verify that the sequence exists or create it
def self.verify(name, create = true, initial_value=1)
name.downcase!
@borgand
borgand / testlistener.rb
Created November 6, 2012 12:55
Listen and Pry debugging testcase
require 'listen'
require 'rb-readline' # <-- adding this fixes issues
require 'pry'
class MyGuard
attr_reader :thread
def initialize(dir)
callback = ->(*args){puts; puts "Got change: #{args.inspect}"}
@listener = Listen.to(dir).change(&callback)
@borgand
borgand / hello_world.rage
Created October 9, 2012 13:40
Rage programming language
# Variable declaration
le text = "Hello, Rage!"
le number = 2
# Begin block with error handling
my poorly drawn code
# Conditionals
number < 3 seriously?
U don't say?
@borgand
borgand / application_helper.rb
Created May 8, 2012 11:32
Rails HAML helper method to display Twitter Bootstrap alert boxes
module ApplicationHelper
# Display alert box with message or optional block
def alert_box(alert_type = :info)
haml_tag :div, :class => 'row-fluid' do
haml_tag :div, :class => "span9 alert alert-#{alert_type}" do
haml_tag :a, '×', :class => 'close', :'data-dismiss' => 'alert'
block_given? ? yield : msg
end
end
@borgand
borgand / nginx_mass_vhosts.conf
Created April 17, 2012 20:40
Nginx mass-virtualhosting with Unicorn and rails
# Mass-virtualhosting configuration for Nginx
# Sets up virtualhosts automatically, in the following way:
# test1.laas.tjs.ee -> /srv/laas/test1
# app.tjs.ee -> /srv/prod/test1
server {
# enable one of the following if you're on Linux or FreeBSD
listen 80 default deferred; # for Linux
# If you have IPv6, you'll likely want to have two separate listeners.
@borgand
borgand / devise.et.yml
Created April 16, 2012 10:36
Estonian translation for Devise
# encoding: utf-8
et:
errors:
messages:
expired: "on aegunud, palun küsi uus"
not_found: "ei leitud"
already_confirmed: "on juba kinnitatud, proovi sisse logida"
not_locked: "ei olnud lukus"
not_saved:
@borgand
borgand / config.ru
Created October 17, 2011 08:37 — forked from mislav/config.ru
Shortest simplest sweetest web "hello {NAME}" in Ruby
run ->(e){ n=e['PATH_INFO'][1..-1]; [200, {'Content-type'=>'text/html'}, ["Hello #{n}!"]] }
@borgand
borgand / pow
Created June 23, 2011 15:50 — forked from ches/pow
A quick script to switch between running Pow and MacPorts Apache2 on OS X
#!/bin/sh -e
#/ Usage: pow [on|off]
#/ Toggle between running Pow (http://pow.cx) and Apache on Mac OS X.
# Show Usage
function usage {
grep '^#/' "$0" | cut -c4-
exit 2
}
[ -z "$1" -o "$1" = "--help" ] && usage
@borgand
borgand / mmo_test.rb
Created December 1, 2010 08:08
Testing Mmo#styles_fit
require 'test_helper'
require 'mocha'
class MmoTest < ActiveSupport::TestCase
# Set up equivalence classes for the tests
def setup
# Equivalence classes
@styles = {
"video" => {