Skip to content

Instantly share code, notes, and snippets.

View dladowitz's full-sized avatar

David Ladowitz dladowitz

View GitHub Profile
@dladowitz
dladowitz / address.rb
Created July 17, 2012 05:05
Active Record Tests
require 'active_record'
require 'sqlite3'
require 'logger'
# ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
:database => 'address_book.db'
ActiveRecord::Base.connection.execute <<-SQL
@dladowitz
dladowitz / cust_router.rb
Created July 19, 2012 21:53
Custom Routes
RouterTester::Application.routes.draw do
resources :companies do
member do
put 'location'
end
end
resources :managers do
@dladowitz
dladowitz / routes.rb
Created July 19, 2012 22:58
Non Rest Routes
RouterTester::Application.routes.draw do
get "managers/index"
get "managers/show"
get "managers/new"
get "managers/create"
get "managers/update"
@dladowitz
dladowitz / new.html.erb
Created August 5, 2012 00:56
Steps for Me Stripe file
<form action="/cards" method="post" id="payment-form">
<div class="form-row">
<script type="text/javascript" src="https://js.stripe.com/v1/">
<script type="text/javascript">
// this identifies your website in the createToken call below
$(document).ready(function(){
Stripe.setPublishableKey('pk_07T3vzpNsDZ1R1f6EXJUiQKC0u0qK');
});
@dladowitz
dladowitz / timer.rb
Created October 26, 2012 00:10
Testing timers using Benchmark vs start/end/ diffing
require 'benchmark'
def janky(length)
start_time = Time.now
(1..length).each { |num| num }
time = Time.now - start_time
time
end
def benchmarked(length)
def check_admin_devices
count = 0
AdminDevice.limit.all.each do |admin_device|
device = Device.find(admin_device.id)
unless device.last_run_time_tester
puts "'last_run_time_tester' was false: #{admin_device.description}"
count += 1
end
end
@dladowitz
dladowitz / payday.rb
Created March 17, 2014 08:00
Given a date, this class is used to find the next payday being the 1st or the 15th. If the payday falls on a weekend or holiday the payday is adjusted to the business day. Note that you'll need to install the gems 'holidays' and 'active_support'. Not sure if this last on if available outside of rails
require 'date'
require 'active_support/core_ext/integer/inflections' # Used for printing date as human text
require 'holidays' # Gives access to holiays
class Payday
def initialize(query_date)
@query_date = query_date
@next_payday = 'unknown'
end
@dladowitz
dladowitz / gist:9595604
Created March 17, 2014 08:11
First Pass at Payday class
require 'date'
require 'active_support/core_ext/integer/inflections'
class Payday
def self.get_next_payday(date)
payday = Payday.get_next_standard_payday(date)
payday = Payday.weekend_adjustment(payday)
"Payday will be " + payday.strftime("%a %b #{payday.day.ordinalize}")
require 'json'
require 'rest-client'
#get a big block of json
github_json = RestClient.get('https://api.github.com/users/rails/repos')
#format the json for ruby to read
ghub_json = JSON.load(github_json)
#loop over all the repos in the formatted json
class Person
attr_accessor :name, :age
def initialize
puts "name: #{name}"
puts "@name: #{@name}"
name = "David"
@name = "Tom"