Skip to content

Instantly share code, notes, and snippets.

View dladowitz's full-sized avatar

David Ladowitz dladowitz

View GitHub Profile
@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
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 / 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)
@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 / 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 / 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 / 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 / student2.rb
Created July 17, 2012 00:19
Active Record Tests
require 'active_record'
require 'sqlite3'
ActiveRecord::Base.establish_connection :adapter => 'sqlite3',
:database => 'db/students.db'
ActiveRecord::Base.connection.execute <<SQL
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
birthday DATE,
@dladowitz
dladowitz / assesment_1_Javascript.js
Created July 7, 2012 05:12
Javascript Assesement 1
// David Ladowitz
// start time: 8:00pm
// Exercise 1....................................................
var newConcat = function(first, last){
return (first + last)
};
newConcat('david', 'ladowitz')
@dladowitz
dladowitz / todo.xml
Created July 3, 2012 18:49
Todo Table XML
<?xml version="1.0" encoding="utf-8" ?>
<!-- SQL XML created by WWW SQL Designer, http://code.google.com/p/wwwsqldesigner/ -->
<!-- Active URL: http://socrates.devbootcamp.com/sql.html -->
<sql>
<datatypes db="mysql">
<group label="Numeric" color="rgb(238,238,170)">
<type label="Integer" length="0" sql="INTEGER" re="INT" quote=""/>
<type label="Decimal" length="1" sql="DECIMAL" re="DEC" quote=""/>
<type label="Single precision" length="0" sql="FLOAT" quote=""/>
<type label="Double precision" length="0" sql="DOUBLE" re="DOUBLE" quote=""/>