Skip to content

Instantly share code, notes, and snippets.

View markauskas's full-sized avatar

Tomas Markauskas markauskas

View GitHub Profile
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
daemon_options = {
:multiple => false,
:dir_mode => :normal,
:dir => File.join(dir, 'tmp', 'pids'),
:backtrace => true
#UserService for GoogleAppEngine JRuby Sinatra apps
#Based on Ola Bini's Beeu
require 'java'
module US
import com.google.appengine.api.users.UserServiceFactory
Service = UserServiceFactory.user_service
end
def current_user
if US::Service.user_logged_in?
#!/bin/bash
# Unattended REE/Passenger installation
# Source: http://weblog.brightlight-ict.nl/2008/12/unattended-passenger-ruby-enterprise-installation-on-ubuntu-8/
# 15/03/09 Updated to use latest r.e.e. and passenger 2.1 and rewrote bits thanks to the comments left on my blog. Thanks guys
if [ "$(whoami)" != "root" ]; then
echo "You need to be root to run this!"
exit 2
fi
@markauskas
markauskas / update_protected_attributes.rb
Created March 2, 2009 21:47
update_all_attributes enables you to mass-assign values to all attributes (also protected ones). Usefull in admin controllers.
class UpdateProtectedAttributes < ActiveRecord::Base
def update_attributes(attributes, guard_protected = true)
self.send(:attributes=, attributes, guard_protected)
save
end
def update_attributes!(attributes, guard_protected = true)
self.send(:attributes=, attributes, guard_protected)
save!
end
# When using has_and_belongs_to_many:
create_table (:lefts_rights, :id => false) do |t|
t.references :left, :null => false
t.references :right, :null => false
end