Skip to content

Instantly share code, notes, and snippets.

View nthj's full-sized avatar

Nathaniel Jones nthj

  • Orlando, FL
View GitHub Profile
@nthj
nthj / car.rb
Created December 4, 2013 17:41
Class vs Instance
class Car
class << self
def advertise(model)
puts "BUY IT NOW! #{model}"
end
def manufacture(make)
def ask_for_age(name)
# We have to ask for this person's age
print "What is #{name}'s age? "
rand(100) # gets.chomp.to_i
end
# Roomful of People
@nthj
nthj / javascript_generator.rb
Created October 25, 2013 20:16
Add this to `lib/generators/javascript_generator.rb`
class JavascriptGenerator < Rails::Generators::NamedBase
def create_javascript_files
create_file "app/assets/javascripts/#{file_name}.coffee", "# New JavaScript File"
create_file "spec/javascripts/#{file_name}_spec.coffee", <<-SPEC
describe "test for #{file_name}", ->
@nthj
nthj / Procfile
Created October 24, 2013 07:56
Running background workers on Heroku without paying for extra dynos
console: bundle exec rails console
rake: bundle exec rake
web: daemonized-worker & web
worker: worker
@nthj
nthj / expirable.rb
Created October 24, 2013 06:03
Expirable Concern for Rails
# Expirable is a module that lets you easily cache
# groups of records, either across an entire record:
# cache(Snippet) => cache(Snippet.cache_key)
# or, across a scope:
# cache(page.blocks) => cache(page.blocks.cache_key)
#
# Why not just use `maximum(:updated_at)`?
# Because it requires 2 queries: the total count,
# and the updated_at timestamp
$(document).ready(function(){
// Explicitly set the left positioning,
// based on the current position calculated by the Browser.
// This "locks" the sidebar to its current x-axis, even
// when we change the positioning strategy in a moment
$('#sidebar').css('left', $('#sidebar').offset().left + 'px');
$(window).scroll(function(){
// Has the visitor scrolled down past the headmast?
// If the headmast is 100 pixels tall, and
@nthj
nthj / gist:5861886
Created June 25, 2013 20:04
calculator
def calculator(operator, expression, *exprs)
exprs.each { |n| expression = expression.send(operator, n) }
expression
end
rails_admin do
configure :expertise do
bootstrap_wysihtml5 true
end
edit do
group 'Login' do
field :email
field :password do
visible false
@nthj
nthj / gist:5297916
Last active December 15, 2015 17:39 — forked from shripadk/gist:552554
How to setup Heroku Hostname SSL with GoDaddy SSL Certificate and Zerigo DNS
Heroku recently added an exciting new 'Hostname SSL' option. This option offers the broad compatibility of IP-based SSL, but at 1/5 the price ($20 / month at the time of this writing).
The following tutorial explains how to use Heroku's new 'Hostname SSL' option on your Heroku project. Before we begin, let's list what we're using here:
* Heroku Hostname SSL
* GoDaddy Standard SSL Certificate
* Zerigo DNS
Note: I am not using the Heroku Zerigo DNS add-on, instead I have a separate Zerigo account for my DNS needs. I do this because Zerigo offers 30 hosts on free direct accounts, versus only 10 hosts on the free Heroku add-on.
@nthj
nthj / rpn.rb
Last active December 11, 2015 14:29
Reverse Polish Notation
def rpn expression
stack = []
expression.split(' ').each do |token|
stack << if token =~ /\d/
token
else
[stack.pop, stack.pop].map { |t| t.to_i }.inject do |sum, x|
eval "#{x} #{token} #{sum}"
end