This file contains hidden or 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 'io/console' | |
# Reads keypresses from the user including 2 and 3 escape character sequences. | |
def read_char | |
STDIN.echo = false | |
STDIN.raw! | |
input = STDIN.getc.chr | |
if input == "\e" then | |
input << STDIN.read_nonblock(3) rescue nil |
This file contains hidden or 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
# via http://www.megasolutions.net/ruby/Getting-the-size-of-the-terminal-in-a-portable-way-26006.aspx | |
TIOCGWINSZ = 0x40087468 | |
def get_winsize | |
str = [0, 0, 0, 0].pack('SSSS') | |
if STDIN.ioctl(TIOCGWINSZ, str) >= 0 | |
rows, cols, xpixels, ypixels = str.unpack("SSSS") | |
p rows, cols, xpixels, ypixels | |
else | |
puts "Unable to get window size" |
This file contains hidden or 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 'net/http' | |
require 'uri' | |
COLOR_SOURCE_VALUES = 256 | |
COLOR_TARGET_VALUES = 5 | |
COLOR_DIVIDE = COLOR_SOURCE_VALUES / COLOR_TARGET_VALUES | |
TERM_COLOR_BASE = 16 | |
def rgb_to_xterm(r, g, b) # part of grosser.it/2011/09/16/ruby-converting-html-colors-24bit-to-xtermterminal-colors/ |
This file contains hidden or 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
function lsgems() { | |
rubyversion=$(ruby -v | cut -f2 -d' ' | sed 's/p/-p/') | |
gemroot=~/.rvm/gems/ruby-"$rubyversion"/gems | |
ls "$gemroot" | |
} | |
function cdgem() { | |
rubyversion=$(ruby -v | cut -f2 -d' ' | sed 's/p/-p/') | |
gemroot=~/.rvm/gems/ruby-"$rubyversion"/gems |
This file contains hidden or 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
# http://ruby-doc.org/stdlib-1.9.3/libdoc/net/smtp/rdoc/Net/SMTP.html | |
require 'digest/md5' | |
require 'mime/types' | |
require 'net/smtp' | |
require 'optparse' | |
require 'ostruct' | |
require 'yaml' | |
class Emailer |
This file contains hidden or 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/ruby | |
#Returns an email dictionary that includes all of an emails headers as well as each part of the email | |
#You can reference which part of the email you'd like by its content type | |
#Ex: email['parts']['text/html'] will get you the text/html version of the email body | |
#You can reference headers by the header name | |
#Ex: email['headers']['To'] will return the value of the "to" field | |
def headers_and_parts(file_path) | |
headers = {} | |
file = File.new(file_path, "r") |
This file contains hidden or 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 A | |
@@class_var = 'aclassvar' | |
@class_instance_var = 'aclassinstancevar' | |
def initialize | |
@instance_var = 'ainstance_var' | |
end | |
def A.class_method |
This file contains hidden or 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 ActionDispatch::Routing::Mapper | |
def draw(routes_name) | |
instance_eval(File.read(Rails.root.join("config/routes", "#{@scope[:shallow_prefix]}", "#{routes_name}.rb"))) | |
end | |
end | |
BCX::Application.routes.draw do | |
draw :projects # => config/routes/projects.rb | |
namespace :admin do |
This file contains hidden or 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
# Beginning Rubyists: simply run >> ruby hex-convertions.rb to see examples | |
# or use irb to build the code on the fly | |
# you can convert HEX to DEC using the method .to_i(base), | |
# which converts a string to a decimal number from the specified base number | |
puts "00".to_i(16) | |
puts "FF".to_i(16) |
This file contains hidden or 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 'pathname' | |
require 'fileutils' | |
#This assumes this script is your home directory level Rakefile | |
namespace :dotfiles do | |
desc "Link ALL the dotfiles!" | |
task :link do | |
path = Pathname.new("#{__FILE__}").dirname | |
Dir.glob "#{path}/Dotfiles/*" do |f| |