This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RequireLoggedUser | |
protected | |
def require_logged_user! | |
before_filter do | |
return true if current_user.present? | |
# if the method hasn't returned, there is no user logged in! | |
# flash a warning and redirect the user to the log in page | |
flash[:warning] = "You must log in before proceeding!" | |
redirect_to new_user_session_path and return | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
around_filter do |controller, action| | |
@start_time = Time.now | |
set_trace_func proc { |event, file, line, id, binding, classname| | |
if (@file != file && @line != line) | |
@file, @line = file, line | |
if (%w(call c-call).include? event) | |
file = @file[(Rails.root.to_s.size+1)..-1] | |
if @file[0...(Rails.root.to_s.size)] == Rails.root.to_s && !(file =~ /vendor\/plugins\/newrelic_rpm/) | |
@logger ||= Logger.new(File.join(Rails.root,'tmp/trace')) | |
args = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HashToArrayWithOrder | |
class MaxDepth < Exception ; end | |
def self.new(data,max_level = 5) | |
raise MaxDepth if max_level==0 | |
if data.is_a? Hash | |
data = data.sort{|a,b| a.class == b.class ? a.to_s <=> b.to_s : a.class.to_s <=> b.class.to_s} | |
end | |
return data unless data.is_a? Array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# This fork add support for running code in a forked process | |
# | |
# encoding: UTF-8 | |
# | |
# LearnRubyByExample: | |
# | |
# Ruby is a highly expressive programming language. | |
# Testing software is an expressive way to communicate how it works. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Search < OpenStruct | |
def to_hash | |
@table | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require File.dirname(__FILE__)+'/../config/environment' | |
ActiveRecord::Migration.create_table(:isam_items, :options => 'ENGINE=MyIsam DEFAULT CHARSET=utf8') do |t| | |
t.string :item_type | |
end | |
ActiveRecord::Migration.create_table(:inno_items, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8') do |t| | |
t.string :item_type | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RackEnvironment | |
def initialize(app) | |
@app = app | |
@environments = {} | |
@changes = lambda {} | |
yield self | |
end | |
def call(env) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'twitter' | |
# TwitterBackup.new(user,pass).backup! | |
# Will save tweets to files | |
# ~/.twitter_backup/tweets/tweet_id.yaml # Full yaml tweet | |
# ~/.twitter_backup/tweets/tweet_id.txt # Only tweet text | |
# Search locally in your tweets | |
# cat ~/.twitter_backup/tweets/*.txt | grep -i 'some text' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Testing gist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mkdir -p /usr/local/src && cd /usr/local/src | |
curl -O ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.bz2 | |
tar -xjvf ruby-1.9.1-p0.tar.bz2 | |
cd ruby-1.9.1-p0 | |
./configure --prefix=/usr --program-suffix=19 --enable-shared | |
make && make install |