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 "money" | |
class Decorator < BasicObject | |
undef_method :== | |
def initialize(component) | |
@component = component | |
end | |
def method_missing(name, *args, &block) |
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 'terminal-table' | |
def unpack_str_table(unpack_str, data = nil) | |
len = unpack_str.scan(/\d+/) | |
sum = 0; idx = 1 | |
fields = len.map { |x| sum += x.to_i } | |
headings = %w( Index Length Start End ) | |
headings << "Data" unless data.nil? | |
table = Terminal::Table.new :headings => headings | |
fields.each do |stop| |
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
#credit to: http://phrogz.net/simplest-possible-ruby-web-server | |
ruby -rrack -e "include Rack;Handler::Thin.run Builder.new{run Directory.new''}" |
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 'securerandom' | |
SecureRandom.urlsafe_base64(8) |
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
source 'https://rubygems.org' | |
gem 'jdbc-sqlite3', :platform => :jruby | |
gem 'sequel' |
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
DB = Sequel.connect('jdbc:sqlite::memory:') | |
DB.create_table(:categories) do | |
Integer :id, :primary_key => true | |
foreign_key :parent_id, :categories | |
String :name, :null => false | |
end | |
DB[:categories].import([:id, :parent_id, :name], [[1, nil, 'GPS'], [2, 1, 'Vehicle GPS'], [3, 1, 'Handheld GPS'], [4, nil, 'GPS Accessories']]) | |
DB.create_table(:products) do |
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 'bcrypt' | |
require 'pp' | |
secret = 'my password' | |
BCrypt::Engine.cost = 4 # default is 10 | |
password = BCrypt::Password.create(secret) | |
puts '********** create **********' | |
puts ['version:', password.version].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
require 'sequel' | |
require 'csv' | |
csv_records = CSV.read('records.csv') | |
DB = Sequel.connect('jdbc:sqlite::memory:') | |
DB.create_table(:records) do | |
Integer :id, :primary_key => true | |
String :member_id, :null => false |
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 'uri' | |
require 'pp' | |
require 'pathname' | |
url = URI('http://66.55.135.155:8000/Channel1') | |
##### VLC ##### | |
stop_time = ARGV.shift # duration in secords | |
abort 'no stop tiime defined' unless stop_time |
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
ds_1 = People.select(:birth).select_append{year(:birth).as(:year)} | |
ds_1.first ##<Member @values={:birth=>1980-09-15 00:00:00 -0700, :year=>1980}> | |
ds_2 = People.select(:birth).select_append{(year(:birth) % 100 ).as(:year)} | |
# ds_2.first | |
# NoMethodError: undefined method `%' for #<Sequel::SQL::Function @name=>:year, @opts=>{}, @args=>[:birth]> | |
# Mostly because it is less common. It's defined in BitwiseMethods, which is only included in NumericExpression by default. | |
# Some of the BitwiseMethods overlap with the BooleanMethods that are included in GenericExpression. |
OlderNewer