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
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com | |
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below) | |
module Player | |
describe MovieList, "with optional description" do | |
it "is pending example, so that you can write ones quickly" | |
it "is already working example that we want to suspend from failing temporarily" do | |
pending("working on another feature that temporarily breaks this one") |
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
# usage Timespan.to_words (Time.now + 10) | |
# usage t_one = Time.now | |
# usage t_two = Time.now + 100 | |
# usage Timespan.to_words t_one | |
# usage Timespan.to_words t_one..t_two | |
class Timespan | |
def self.to_words(time) | |
unless (time.is_a?(Time) or (time.is_a?(Range) and (time.first.is_a?(Time) and time.last.is_a?(Time))) ) | |
raise 'Time should be a Time/(Range in Time) object #{time.class} given' |
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
def generate_sequence(str) | |
list = [str.downcase] | |
while (num = list.find{|s| s.index 'x'}) | |
list = list + get_list(list.delete num) | |
end | |
list | |
end | |
def get_list(str) | |
loc_x = str.index 'x' |
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
def cmd_exe(cmd, &block) | |
output = nil | |
log_to_scribe("JR-ncpr-upload"," executing command #{cmd}") | |
Open3.popen3(cmd) do |stdin, stdout, stderr| | |
output = stdout.readlines | |
error = stderr.readlines | |
unless error.empty? | |
p "#{cmd} Failed " | |
log_to_scribe("JR-ncpr-upload","#{cmd} Failed, with error #{error.to_s}") | |
yield false if block_given? |
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 'open3' | |
def cmd_exe(cmd, &block) | |
output = nil | |
Open3.popen3(cmd) do |stdin, stdout, stderr| | |
output = stdout.readlines | |
error = stderr.readlines | |
p error | |
unless error.empty? | |
p "#{cmd} Failed " | |
yield false if block_given? |
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 'active_support/core_ext/hash/keys' | |
class Hash | |
def recursively_symbolize_keys! | |
self.symbolize_keys! | |
self.values.each do |v| | |
if v.is_a? Hash | |
v.recursively_symbolize_keys! | |
elsif v.is_a? Array | |
v.recursively_symbolize_keys! |
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 'eventmachine' | |
# Code adapted from EM's tests: | |
# https://github.com/eventmachine/eventmachine/blob/master/tests/test_processes.rb#L43 | |
ls = "" | |
EM.run { | |
start_process = Proc.new do |id| | |
d = EM::DeferrableChildProcess.open( "/bin/bash -c 'slee 1 2> /tmp/err-em.log'" ) | |
d.callback {|*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
# template for | |
class ForkedProcess | |
def initialize *args | |
end | |
def receive_data data | |
#EM.popen form_cmd, ForkedProcess | |
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
#ruby -v # 1.9.2 | |
#gem list|grep em-ssh # em-ssh(0.1.0) | |
require 'em-ssh' | |
# runs the command on server and gives the callback call | |
def do_ssh(cmd) | |
do_ssh_var = 'ssh' | |
EM::Ssh.start('localhost','goutham') do |ssh| | |
puts 'ssh start' | |
ssh.exec!(cmd) do |channel, stream, data| |
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
# in /app/models/tag_note.rb | |
class TagNote < ActiveRecord::Base | |
belongs_to :tag | |
end | |
# in /app/models/acts_as_taggable_on/tag.rb | |
class ActsAsTaggableOn::Tag | |
has_one :tag_note | |
end |
OlderNewer