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 | |
# | |
# 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 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
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
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
[root@es01 ~]# hdparm -Tt /dev/sda1 | |
/dev/sda1: | |
Timing cached reads: 10004 MB in 2.00 seconds = 5012.25 MB/sec | |
Timing buffered disk reads: 14 MB in 3.38 seconds = 4.14 MB/sec | |
[root@es01 ~]# dd if=/dev/urandom of=/tmp/urandom count=100000 | |
100000+0 records in | |
100000+0 records out | |
51200000 bytes (51 MB) copied, 14.4699 seconds, 3.5 MB/s |
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
debug = () -> | |
s = "" | |
for arg in arguments | |
unless typeof(arg) == "string" | |
arg = JSON.stringify arg | |
s += "#{arg} :" | |
window.console.debug s |
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 | |
=begin | |
README | |
====== | |
Download any youtube video, in the original format ogg without | |
loosing quality, and also convert a mp3 from the ogg. | |
You have to decide if the mp3 quality is enough for you. Or you | |
can adjust the parameters of the conversion if you need the mp3 |
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 Utils | |
extend self | |
def install | |
puts "Installing" | |
end | |
end | |
desc "We are going to install... LA LA LA" |
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
# Option 1 | |
# The clean one, you can move the class to other file | |
module Utils | |
extend self | |
def install | |
puts "Installing" | |
end | |
end |