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 Object | |
def self.sub_constants(prefix = "", namespace=[]) | |
self.constants.each do |constant| | |
constant = constant.to_s | |
puts prefix + constant | |
#puts eval("#{constant}.methods").inspect | |
begin | |
next if %w{ Object Module Class }.include?(constant) || namespace.include?(constant) | |
b = (namespace.dup) << constant | |
eval_string = b.join('::') |
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 Mojule | |
def dynamic_method | |
if self.class.eql?(Class) | |
puts "I am now a class method of #{self.name}" | |
else | |
puts "I am now an instance method of #{self.class}" | |
end | |
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
# Use tshark to grep custom header key value (HEADER_KEY) out of responses from a local rails server | |
tshark -i eth0 -d tcp.port==3000,http tcp port 3000 -V -R "http.response" | grep HEADER_KEY -B 10 -A 10 |
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
# Enumerator to loop with | |
months = (1..12).to_a.reverse.each | |
# Integer to loop with | |
year = 1000 | |
# month counts down, then resets through loop | |
# year goes up to 2014 then ends | |
until year == 2014 do | |
begin |
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
# app/helpers/my_model_helper.rb | |
class MyModelValidator < ActiveModel::Validator | |
def validate(mymodel) | |
unless mymodel.starts_at.nil? || mymodel.ends_at.nil? | |
validate_times(mymodel) | |
end | |
end | |
def validate_times(mymodel) |
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
" bind \f to run rspec on current file | |
:map \f :w\|!rspec %<cr> | |
" bind \l to run rspec on current line | |
:map \l :w\|:exe "!rspec % -l " . line('.')<cr> | |
" bind \w to run rspec on current file | |
" this one kind of sucks... | |
:map \w :w\|:exe "!rspec % -e " . expand("<cword>")<cr> |
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
# helps you play twister... | |
# yup.... | |
class Twister | |
def colors | |
%w{ red blue yellow green } | |
end | |
def left_right |
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/bash | |
# counts all lines in all ruby files in a directory | |
find . -type f -name *.rb -exec cat {} \; | grep -vE "^([[:space:]]+)?\#" | grep -vE "^([[:space:]]+)?$" | wc -l |
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
# Simple Serial Listener I have used to listen to Arduino from Ubuntu. | |
# That is all. | |
require "serialport" | |
#params for serial port | |
port_str = "/dev/ttyACM0" #may be different for on different machines | |
baud_rate = 9600 | |
data_bits = 8 | |
stop_bits = 1 |
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
# Ways to execute a shell script in Ruby | |
# Example Script - Joseph Pecoraro | |
cmd = "echo 'hi'" # Sample string that can be used | |
# 1. Kernel#` - commonly called backticks - `cmd` | |
# This is like many other languages, including bash, PHP, and Perl | |
# Returns the result of the shell command | |
# Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |
OlderNewer