Skip to content

Instantly share code, notes, and snippets.

View nateberkopec's full-sized avatar

Nate Berkopec nateberkopec

View GitHub Profile
module Mokha
class HomeController < Mokha::BaseController
def index
@view = Mokha::HomePresenter.new
@view.user = User.includes(:ratings).find(current_user)
@view.user.track('Opened Mokha')
end
number_of_colors = 60 #number of colors you want to generate in total.
z = 12 #"set size"
ang = 180/(z)
s = 30 #desired saturation constant, 1 to 100
v = 50 #desired value/lightness constant, 1 to 100
complement = (0..z/2).map{|i| (0..180).step(ang).map{|h| [[h + i,s,v], [h + i + 180,s,v] }}
triad = (0..z/2).map{|i| (0..180).step(ang).map{|h| [[h + i,s,v], [h + i + 60,s,v], [h + i + 120,s,v]] }}
@nateberkopec
nateberkopec / secure_headers.rb
Created March 28, 2013 19:44
Example of a simple Rack middleware for scrubbing your Rack headers of sensitive information.
class Rack::SecureHeaders
def initialize(app, options = {})
@app, @options = app, options
end
def call(env)
response = @app.call(env)
# [status, headers, response] = response
@nateberkopec
nateberkopec / kill_me_now.rb
Created March 29, 2013 19:49
kill_me_now.rb
Product.metaclass.send(:define_method, name.to_s) do
-> { Product.send(:relation).order(order_text) }
end
@nateberkopec
nateberkopec / gist:5289274
Created April 2, 2013 01:33
current status
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░██░░░░░░██░░█████░░░██░░░░░░█████░░░
░░██░░░░██░░██░░░██░░██░░░░░██░░░██░░
░░░██░░██░░░██░░░██░░██░░░░░██░░░██░░
░░░░████░░░░██░░░██░░██░░░░░██░░░██░░
░░░░░██░░░░░██░░░██░░██░░░░░██░░░██░░
░░░░░██░░░░░██░░░██░░██░░░░░██░░░██░░
░░░░░██░░░░░░█████░░░██████░░█████░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░█████░░░██░░░██░░░█████░░░█████░░░
#Subscription has_one :user
#Order has_many :subscriptions
sub = Subscription.new(user: User.new)
order = Order.new
order.subscriptions += [sub]
# order.subscriptions.first.user == nil
@nateberkopec
nateberkopec / delayed_job.rb
Created April 12, 2013 01:42
Comparison of top 3 Ruby background job systems on Ruby Toolbox
# DelayedJob
@user.delay.activate!(@device) # Delay any object
Notifier.delay.signup(@user) # Delay ActionMailer
#DelayedJob supports a number of ways to make methods async
def send_mailer
# Some other code
end
handle_asynchronously :send_mailer, :priority => 20
@nateberkopec
nateberkopec / gist:5714795
Last active January 6, 2020 17:33
Fixing your Nokogiri config
# IF NOKOGIRI 1.5.X OR LOWER
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
bundle config --global build.nokogiri "--with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2"
bundle
@nateberkopec
nateberkopec / gist:5716233
Last active April 2, 2019 08:20
round the world in seven whiskeys

round the world in seven whiskeys, if youve drank these seven you'll have an idea of what whiskeys can do. i've deliberately picked "extreme flavored" scotches rather than necessarily "good" ones, to ensure the maximum flavor range possible. there are better islays, speysides, ryes, etc, but my intention is to show the wide flavor of high end whiskies.

  1. islay - Laphroaig Triple Wood or Laphroaig cask strength
  2. speyside - glenlivet, glenfiddich, highland park, or macallan, aim for 15 year or above.
  3. wooded - Balvenie Caribbean Cask 14 year, or any scotch with wood in the name.
  4. rye - no good recommendation here, but try one.
  5. bourbon - heavily aged. Jefferson Select 18 year is avaiable in high-end bars in NYC.
  6. sherried - Bruichladdich Black Art or any of the Macallan sherries
  7. corn - essentially "double bourbon". not a lot of high end stuff, but try Hudson.
class Subscription
belongs_to :gifter, :class_name => 'User', :foreign_key => :gifter_id
end
@user = User.first
Subscription.where(gifter: @user)
# ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR: column subscriptions.gifter does not exist