Skip to content

Instantly share code, notes, and snippets.

View compwron's full-sized avatar
💭
https://github.com/drop-ice/dear-github-2.0

compwron compwron

💭
https://github.com/drop-ice/dear-github-2.0
View GitHub Profile
@compwron
compwron / unused_date_format_finder.rb
Created February 7, 2015 06:15
find unused date formats
a = "apache
batch_name
datetime_with_seconds
download_csv_datetime
download_csv_timezone
expiration
mmdd
mmyy
hhmmss
iso8601_milliseconds
@compwron
compwron / gist:b1b7380bf61d8d4f2814
Created February 8, 2015 18:10
modify array in place
class Array
def square!
self.map! {|i| i ** 2}
end
end
a = [1, 2, 3]
a.square!
if a == [1, 4, 9]
class OrbitalCoordinate
def initalize(lat, long, altit)
@lat = lat
@long = long
@altit = altit
# @veloc = veloc # meters per second
# how many seconds it will take to get to another point.
OrbitalVelocity..new(sec, OrbitalCoordinate)
end
end
@compwron
compwron / gist:00c94fc3b92bff925d25
Created March 13, 2015 22:09
nested parameters for enumerable block
irb(main):015:0> (0..4).each_with_index.map.inject(0) {|i, (j, k)| puts "i: #{i} j: #{j} k: #{k}" ; i }
i: 0 j: 0 k: 0
i: 0 j: 1 k: 1
i: 0 j: 2 k: 2
i: 0 j: 3 k: 3
i: 0 j: 4 k: 4
=> 0
irb(main):016:0>
@compwron
compwron / gist:32f4595a22bc5a61a426
Created March 15, 2015 17:28
gmail monitor and filesender
/* PayPal Shop with Apps Script */
/* Written by Amit Agarwal - ctrlq.org */
/* http://www.labnol.org/internet/sell-digital-products-online/28554/ */
PAYPAL = [
["product-001", "useful-websites-book.pdf"],
["product-002", "linux-training-course.mp4"],
module Foo
def bar
"stuff"
end
end
World Foo # world-accessible
# pry(main)> method(:World).owner
# => Cucumber::RbSupport::RbDsl
# http://www.rubydoc.info/github/cucumber/cucumber/Cucumber/RbSupport/RbDsl:World
# Only run the following code when this file is the main file being run
# instead of having been required or loaded by another file
if __FILE__==$0
# Find the parent directory of this file and add it to the front
# of the list of locations to look in when using require
$:.unshift File.expand_path("../../", __FILE__)
end
# http://stackoverflow.com/questions/4687680/what-does-if-file-0-mean-in-ruby
@compwron
compwron / gist:1f92e6b8dc702e842c3c
Created April 13, 2015 22:02
redirecting standard out stdout for tests
class Foo
def initialize out=STDOUT
$stdout = out
end
end
Foo.new(StringIO.new)
@compwron
compwron / gist:2a99d494b489d2cb4a70
Last active August 29, 2015 14:19
polymorphic has_many_through with dependent destroy
class Fridge < ActiveRecord::Base
has_many :soda_ownerships, dependent: :destroy
has_many :cokes, through: :soda_ownerships, source: :owner, source_type: 'Coke'
has_many :sprites, through: :soda_ownerships, source: :owner, source_type: 'Sprite'
end
class SodaOwnership < ActiveRecord::Base
belongs_to :fridge
belongs_to :owner, polymorphic: true
belongs_to :coke, class_name: 'owner_type', foreign_key: 'owner_id'
@compwron
compwron / gist:f32f13630be15c52b07a
Created May 29, 2015 22:20
load yml files into a class
require 'ostruct'
require 'yaml'
require 'erb'
require 'active_support/core_ext/class/attribute'
require 'active_support/core_ext/hash/indifferent_access'
require 'active_support/core_ext/hash/deep_merge'
require File.expand_path(File.dirname(__FILE__)+'/../config/initializers/openstruct_additions')
class AppConfig
class_attribute :config