Skip to content

Instantly share code, notes, and snippets.

View jimsynz's full-sized avatar
💜

James Harton jimsynz

💜
View GitHub Profile
@jimsynz
jimsynz / api_controller.rb
Created March 19, 2014 01:42
Ember API Token
# app/controllers/api_controller.rb
class ApiController < ApplicationController
skip_before_action :verify_authenticity_token
respond_to :json
rescue_from UserAuthenticationService::NotAuthorized, with: :not_authorized
rescue_from ActiveRecord::RecordNotFound, with: :not_found
before_filter :api_session_token_authenticate!
private
This file has been truncated, but you can view the full file.
..../Users/jnh/.rvm/gems/ruby-2.1.1/gems/rspec-core-2.14.5/lib/rspec/core/memoized_helpers.rb:199: [BUG] Segmentation fault at 0x007fff51ad3fd8
ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-darwin13.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
for more details.
@jimsynz
jimsynz / mr_darcy.rb
Last active August 29, 2015 13:56
So, after our dopodcast episode about DCI (http://dopodcast.org/blog/2014/02/10/show-9-dci-with-jim-gay-and-craig-ambrose/) I've been thinking a lot about the intersection of DCI and Promises/A+ in Ruby, and here's an example of what I've been thinking.
class MrDarcy
class Context
class << self
def role role_name, &block
role_name = role_name.to_sym
roles[role_name] = Module.new(&block)
role_name
@jimsynz
jimsynz / gist:8679147
Created January 29, 2014 00:04
lame arguments I use to create dopodcast mp3s.
lame -V 6 --tt 'Do Podcast: Show 4, Ruby 2.1' --tg 0xc --ta 'Do Podcast' --ty 2013 --tc 'http://dopodcast.org' --ti '~/Dev/dopodcast/dopocast.github.io/source/images/ruby-latte-rss.jpg' 'Do Podcast - Show 4.wav' show_4_ruby21.mp3
@jimsynz
jimsynz / dev_log.txt
Last active December 31, 2015 18:49
Super weirdness:
[1] pry(main)> project = Fabricate(:project_with_attachments)
=> #<Project _id: Lo2ekuTh, created_at: 2013-12-18 04:28:41 UTC, updated_at: 2013-12-18 04:28:41 UTC, design: "design.brd", top_image: "i.png", bottom_image: "i.png", user_id: nil, upload_id: nil, license_id: nil, parent_project_id: nil, name: "Aliquam molestias id.", description: "Vel accusamus reiciendis officia voluptate.\nSed nihil sequi.", short_description: nil, notes: nil, version: nil, state: "CREATING", price: "3.9", email: "louvenia@gmail.com", width_in_mils: 1024, height_in_mils: 768, pcb_layers: 2, shared_at: nil, share_setup_state: nil>
[2] pry(main)> project.layers.size
=> 8
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (1.3313ms)
MOPED: 127.0.0.1:27017 INSERT database=playground_development collection=projects documents=[{"state"=>"CREATING", "price"=>"3.9", "width_in_mils"=>1024, "height_in_mils"=>768, "pcb_layers"=>2, "name"=>"Aliquam molestias id.", "description"=>"Vel accusamus reiciendis of
@jimsynz
jimsynz / 1_source.rb
Last active December 30, 2015 16:09
Surprised that you can't just ram a `rescue` or `ensure` inside a block without an enclosing `begin`.
puts "Trying Ruby #{RUBY_DESCRIPTION}"
eval <<-'EOF'
proc do
puts "hello"
rescue Exception => e
puts "Exception #{e}"
ensure
puts "goodbye"
end
require 'spec_helper'
describe WidgetController do
subject { query; response }
describe '#index' do
let(:query) { get :index, format: :json }
context "when there are widgets available" do
before { Fabricate(:available_widget) }
@jimsynz
jimsynz / gist:7633261
Last active December 29, 2015 06:59
Wouldn't it be super-awesome if you could automatically re-use scenarios as Givens in other scenarios?
Feature: New users can register and confirm accounts
Scenario: A new user registers for our service
Given I am on the home page
When I select "Register" from the nav
And I submit my details
Then I should see the thank you page
And I should receive a confirmation email
Scenario: The new user correctly pastes their confirmation code
isMultipleOf = (n)->
(order)->
order.get('quantity') % n == 0
max = (accumulator, item)->
accumulator = item if item > accumulator
accumulator
isGtZero = (quantity)->
quantity > 0
def send_status_email
# Sometimes a whole bunch of emails will be queued in quick-succession.
# This is to stop them all being sent to the customer. It deletes any
# jobs queued to send this email, and then queues another to happen in
# 1 minute.
applicable_job = proc do |job|
job.klass == 'CartNotifierWorker' && job.args == ['cart_status_changed', self.id]
end
Sidekiq::ScheduledSet.new.select(&applicable_job).map(&:delete)
CartNotifierWorker.perform_in(60.seconds, :cart_status_changed, self.id) if user?