Skip to content

Instantly share code, notes, and snippets.

View doug7410's full-sized avatar

Doug Steinberg doug7410

  • Agile Element
  • Coral Springs, FL
View GitHub Profile
@doug7410
doug7410 / gist:99a02989c3b586eb7aca
Last active August 29, 2015 14:02
Answer to Tea Leaf Academy lesson 1 : make a quiz question
# Question
How can the code below be refactored into one line?
arr = [2,3,4,5]
arr *= 4
arr.shuffle
# Answer
@doug7410
doug7410 / gist:e2ea22f32155085a325c
Created June 1, 2014 23:34
Does a method create it's own scope?
#If you define a method does it create a scope within itself? Don't any variables or methods used within a method need to be passed in as arguments?
#Here's an example
name = "Frank"
def say_hello(n)
def hello_method
"hello"
end
action@tealeaf-115616:~(master*)$ heroku login
/home/action/.parts/packages/heroku_toolbelt/3.5.0/lib/heroku/updater.rb:164:in `spawn': Permission denied - open (Errno::EACCES)
from /home/action/.parts/packages/heroku_toolbelt/3.5.0/lib/heroku/updater.rb:164:in `background_update!'
from /home/action/.parts/packages/heroku_toolbelt/3.5.0/lib/heroku/updater.rb:144:in `inject_libpath'
from /home/action/.parts/bin/heroku:19:in `<main>'
<?php
//get the arrays for US states, Canadian Provences, and both
// the array names are $us_states, $canadian_provences, $state_array
require('state_list.php');
// create an <option> list
//
// takes in a $key => $value array and the name of the <select> element
@doug7410
doug7410 / gist:c051ba842c79c98fc30f
Created July 20, 2014 23:36
finds no matches from search
it "finds no matches from search" do
expect(Video.search_by_title('family')).to eq(nil)
end
@doug7410
doug7410 / gist:eadb5f6a27ed8bd5dcc3
Created July 28, 2014 20:14
video_controller_spec
require 'spec_helper'
describe VideosController do
describe "GET show" do
it "sets the requested video to @video" do
video = Video.create(title: "Game of Thrones", description: "A very awesome show!")
get :show, id: video.id
assigns(:video) == video
end
class VideosController < ApplicationController
before_action :require_user
def show
@video = Video.find(params[:id])
end
def search
@search_phrase = params[:search_term]
def total_time_on_job
total = 0
self.punches.each do |punch|
if punch.punch_out
punch_in_time = punch.created_at
punch_out_time = punch.punch_out
total_time = punch_out_time - punch_in_time
total += total_time
end
@doug7410
doug7410 / gist:7997f41a0326d4b3bd9a
Created December 12, 2014 16:43
create action for sending a notification
def create
if the_customer_is_missing
@notification.errors[:base] << "Please choose a customer or add a new one."
render :index
elsif a_new_customer_is_being_added
if @customer.valid?
send_text_if_notification_and_customer_valid!
else
@notification.errors.clear
render :index
$(document).ready(function(){
$('#individual-notification .notification-container').hide();
$('#individual-notification .header-box').on('click', function(){
$('#individual-notification .notification-container').slideToggle();
});
});