Skip to content

Instantly share code, notes, and snippets.

View davidbegin's full-sized avatar

Begin davidbegin

View GitHub Profile
@davidbegin
davidbegin / gist:5113905
Created March 8, 2013 03:00
Resizing margins based on window size
$('.home_details').css("margin-top", function(){
if ($(window).height() > 642) {
return "0px";
} else {
return (((642 - $(window).height())) / 6.8) + "px";
console.log(737 - ($(window).height()) + "px");
}
});
require 'factory_girl'
FactoryGirl.define do
factory :user do
name 'Pete'
end
factory :registration do
title 'Summer Class'
end
require 'pry'
require 'debugger'
x = %q[This is a dank video <iframe width="560" height="315" src="//www.youtube.com/embed/dGd9DTTrX4U" frameborder="0" allowfullscreen></iframe>]
array = x.split('<iframe')
array.delete('')
new_hash = {}
array.each do |str|
while y != "no":
print ">>>> M value is: ", m
s = int(raw_input(">>> Which Servo? >> "))
if s == 2
# here we need to set it to go up and down
else
m = int(raw_input(">>> Where? >> "))
if m > 149 and m < 601:
pwm.setPWM(s, 0, m)
elif m < 150:
[{
"identifier": "111111",
"name":"ABC Heating and Cooling",
"contact":{"phone":"",
"email":"",
"address":{"street1":"3266 Investment Blvd",
"city":"Hayward",
"state":"CA",
"zipcode":"94545"
}
@davidbegin
davidbegin / contractor_location_example.json
Created May 19, 2015 22:54
Contractor Location Example
{
"location_id" => "aBV0000000000003Estl",
"location_name" => "ABC Heating Jungle Location",
"contractor_id" => "BHh747874000Estbnl",
"dba_name" => "ABC Heating",
"website_url" => "www.abcheating.com",
"contact" => {
"phone" => "555-555-5555",
"email" => "sales@abcheating.com",
"address" => {

Using Pry and Gist together

gem install pry
gem install gist

gist --login # otherwise it will post anon
gist file.rb
# => https://gist.github.com/34ebbc09i62fd7909565
@davidbegin
davidbegin / mind_twister.rb
Last active August 29, 2015 14:26
Ruby mind twister
# 6. The superclass of the singleton class of an object is the object's class.
# The superclass of the singleton class of a class is the singleton class
# of the class's superclass.
class Person; end
p = Person.new
puts p.singleton_class.superclass == p.class #=> true
puts Person.singleton_class.superclass == Person.superclass.singleton_class #=> true
class Person
# We all know this is for putting "class methods"
# on a class
#
# but this is actually a special syntax for moving into the scope
# of a singleton class
#
# in this case we are moving into the scope of self's singleton's
# class
#
@davidbegin
davidbegin / checked_attr_challenge.rb
Created August 11, 2015 04:43
Metaprogramming Challenge
# CheckedAttributes Challenge
#
# Make the following two tests pass
# only by implementing the module CheckedAttributes
class Person
include CheckedAttributes
attr_checked :age do |v|
v >= 18