Skip to content

Instantly share code, notes, and snippets.

View markauskas's full-sized avatar

Tomas Markauskas markauskas

View GitHub Profile
#!/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
#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?
#!/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
# 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!
=== Epic Snow Leopard Upgrayyyyd Guide ===
Son, you’re now living in the land of 64-bit systems.
That means that some of your 32-bit shit is now broken.
Not all is lost.
== Fixing MySQL weirdness
@markauskas
markauskas / landing.rb
Created December 25, 2009 18:18 — forked from mid/landing.rb
require 'rubygems'
require 'sinatra'
require 'haml'
Domains = %w{gemsmith vogsphere youngman seraph intercessory cyaonline significantwhitespace 14159265358979}
DefaultDomain = 'default'
# what domain does the host contain?
# put this here because helpers are a pain to test!
def view_for_domain(host)
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
# Run rake db:size to get a print of your database size in bytes.
# Run rake db:tables:size to get the sizes for individual tables
# Works for MySQL and PostgreSQL. Not tested elsewhere.
namespace :db do
desc 'Print data size for entire database'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase
module ActionController
module Resources
class Resource
# Redefining methods from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/resources.rb so that the RESTful routes accept member_path option
def member_path
@member_path || options[:member_path] || "#{shallow_path_prefix}/#{path_segment}/:id"
end
def default_url_options(options = {})
# resource hack so that url_for(@post) works like it should
# if a post was given as a parameter to `post_path` it will be assigned to the first (unnassigned) parameter of the route (year)
if options[:controller] == "posts" && options[:year].is_a?(Post)
post = options[:year]
options[:year] = post.year
options.merge(:month => post.month, :slug => post.slug)
else
{}
end