Skip to content

Instantly share code, notes, and snippets.

@jordanmaguire
jordanmaguire / rspec_attributes.rb
Created June 26, 2012 01:29
This is a helpful RSpec pattern I've been playing with lately with great success
let(:vehicle) { FactoryGirl.create(:vehicle, vehicle_attributes) }
let(:vehicle_attributes) { {} }
describe "#to_s"
subject { vehicle.to_s }
let(:vehicle_attributes) { {name: "Carzilla"} }
it { should == "Carzilla" }
end
@nfedyashev
nfedyashev / gist:3377341
Created August 17, 2012 09:20
Make strong_parameters work nice with rails_admin
class ApplicationController < ActionController::Base
before_filter :skip_strong_parameters, :if => :rails_admin_path?
def skip_strong_parameters
params.select { |key, value| params[key].kind_of?(ActionController::Parameters) }.map { |key, value| params[key].permit! }
end
privaate
def rails_admin_path?
@mattetti
mattetti / gist:5097178
Last active December 14, 2015 13:58
Rails 4 prod mod hello world (with AR) after warm up. (Ruby 2.0 TracePoint) 248 classes used, 739 methods used, 2490 methods dispatched
{
"ActionDispatch::Static": {
"call": 1
},
"ActionDispatch::FileHandler": {
"match?": 1,
"ext": 1
},
"ActiveSupport::Cache::Strategy::LocalCache::Middleware": {
"call": 1
@Integralist
Integralist / Imager.js
Last active December 21, 2015 01:38
Imager.js (as of 14th August 2013)
(function (window, document) {
'use strict';
var $, Imager;
window.requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
@marktabler
marktabler / Benchmark Notes
Last active December 29, 2015 09:19
Ruby API Framework Benchmarks
Sinatra 1.4.4
Rails 4.0.1
Rails-API 0.1.0
Rails-API disabled Mailer and Sockets
Each app connected to a MySQL database via ActiveRecord with an empty Accounts table; each app's root path responded with "#{Account.count} accounts detected."
Each app was configured to use Thin as its web server.
@katowulf
katowulf / module.simpleLoginTools.js
Last active March 3, 2016 04:26
A service and several directives based on ng-cloak, which wait for angularFire to finish authenticating--rather than just until Angular bootstraps--before displaying it's content. Handy to get rid of those blips that display when user isn't logged in--oh, wait, now they are.
'use strict';
/**
* This module monitors angularFire's authentication and performs actions based on authentication state.
* directives/directive.ngcloakauth.js depends on this file
*
* Modify ng-cloak to hide content until FirebaseSimpleLogin resolves. Also
* provides ng-show-auth methods for displaying content only when certain login
* states are active.
*
@tomdale
tomdale / gist:1856842
Created February 18, 2012 01:54
Ember documentation TODO

Documentation

TODO

  • API docs
  • How to bootstrap a project
  • Application structure (M/V/C layers and what they're for)
  • Getting started with Ember and Rails
  • Built-in controls
  • How events are handled and bubbled
@alexaivars
alexaivars / setter_pattern.coffee
Created January 12, 2012 08:41
Getter Setter patter for Coffeescript
Function::define = (prop, desc) ->
Object.defineProperty this.prototype, prop, desc
class GetterSetterTest
constructor: (@_obj = {}) ->
# 'obj' is defined via the prototype, the definition proxied through
# to 'Object.defineProperty' via a function called 'define' providing
# some nice syntactic sugar. Remember, the value of '@' is
# GetterSetterTest itself when used in the body of it's class definition.
@creationix
creationix / inspect.js
Created December 23, 2010 06:51
a custom object inspector to help me understand JavaScript
function escapeString(string) {
string = string.replace(/\\/g, "\\\\").
replace(/\n/g, "\\n").
replace(/\r/g, "\\r").
replace(/\t/g, "\\t");
if (string.indexOf("'") < 0) {
return "'" + string + "'";
}
string = string.replace(/"/g, "\\\"");
return '"' + string + '"';
require "uri"
(URI::REGEXP.constants - ["PATTERN"]).each do |rc|
puts "#{rc}: #{URI::REGEXP.const_get(rc)}"
end
URI::REGEXP::PATTERN.constants.each do |pc|
puts "#{pc}: #{URI::REGEXP::PATTERN.const_get(pc)}"
end