Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / git-merge-svn
Last active January 7, 2019 06:44
A helper script to set *svn:mergeinfo* property when using `git svn dcommit` on merged git branches.This makes it possible to merge two SVN branches using **git-svn**.NB! the merged-from branch **MUST** be pushed to SVN.USAGE: git merge-svn <branch name>EDIT: added exit condition when mergeinfo calculation fails to avoid pushing incomplete merge…
#!/bin/bash
function usage {
echo "USAGE: git merge-svn <from> [<to>]"
echo ""
echo " from The branch name to be merged FROM"
echo " to Optional branch name to be merged onto. Default: HEAD"
echo ""
}
@borgand
borgand / Asset.php
Last active December 17, 2015 08:59
A SimpleSAMLphp Asset helper to produce MD5-fingerprinted URLs to assets. This allows long-term agressive caching by the browser while retaining instantaneous refreshing when the asset changes. Put this file in some SSP module's lib directory and rename the class name to match the module name (e.g. sspmod_mymodule_Asset).
<?php
/**
* Helper class for working with Assets
*
* @author Laas Toom, University of tartu
*/
class sspmod_utmodule_Asset {
/**
* Get absolute URL to a specified asset.
@borgand
borgand / auth_test.sh
Created September 26, 2013 13:54
Round-trip check for Shibboleth and SimpleSAMLphp SSO setup. Uses sed to carve out tokens, so you must adapt to your HTML layout.
#!/bin/bash
# This script is used make a full roundtrip test to SimpleSAMLphp based SSO
# Exit statuses indicate problem and are suitable for usage in Nagios.
BASENAME=$(basename $0)
if [[ $1 == '-h' || $1 == '--help' ]]; then
cat <<EOF
USAGE: $BASENAME [URL] [test-string] [username] [password]
@borgand
borgand / activeadmin.et.yml
Created February 18, 2014 15:21
ActiveAdmin Estonian translation
et:
active_admin:
dashboard: Töölaud
dashboard_welcome:
welcome: "Tere tulemast Active Adminisse. See on vaikimisi töölaud."
call_to_action: "Et lisada töölauale sektsioonie, uuri 'app/admin/dashboard.rb'"
view: "Vaata"
edit: "Muuda"
delete: "Kustuta"
delete_confirmation: "Oled sa kindel, et soovid seda kustutada?"