Skip to content

Instantly share code, notes, and snippets.

View noahpryor's full-sized avatar

Noah Pryor noahpryor

View GitHub Profile
@carpeliam
carpeliam / db.rake
Created April 15, 2011 02:44
dump, load, or clear a mysql database for a rails project
namespace :db do
desc "Clear all tables"
task :clear => :environment do
conn = ActiveRecord::Base.connection
conn.tables.select{|t| t.start_with? ActiveRecord::Base.table_name_prefix }.each do |t|
conn.drop_table t
end
end
desc "Dump database into an SQL file"
@mattwynne
mattwynne / gist:1228927
Created September 20, 2011 11:52
eventually helper method for making assertions against asynchronous systems
# usage:
# it "should return a result of 5" do
# eventually { long_running_thing.result.should eq(5) }
# end
module AsyncHelper
def eventually(:options = {})
timeout = options[:timeout] || 2
interval = options[:interval] || 0.1
time_limit = Time.now + timeout
loop do
@wdiechmann
wdiechmann / gist:1892556
Created February 23, 2012 12:03
Rendering a string of Erb/HAML back to a string (render :partial from everything else but filesystem)
# My intention is to be able to do this:
#
# from within some view, render a partial
# with the added flavour that the partial is not a file
# but rather a table model instance - like say a Customer,
# a PurchaseOrder, or in this case - a Template
# the partial rendering "should" adhere to all the standard Rails
# magic, ie nested rendering of partials, builders with Erb/HAML,
# I18n translation support to label the most important.
@linjian
linjian / deferred_garbage_collection_all_in_one.rb
Created July 19, 2012 08:09
Deferred Garbage Collection All in One
# http://ariejan.net/2011/09/24/rspec-speed-up-by-tweaking-ruby-garbage-collection
#
# Usage:
# DEFER_GC=10 rspec spec/
# DEFER_GC=10 cucumber features/
#
# put it to spec/support/deferred_garbage_collection_all_in_one.rb
# or feature/support/hooks.rb
class DeferredGarbageCollection
DEFERRED_GC_THRESHOLD = (ENV['DEFER_GC'] || -1).to_f
@benfoxall
benfoxall / MutationObserverLogger.js
Created December 5, 2012 18:10 — forked from pgchamberlin/MutationObserverLogger.js
Snippet that logs DOM mutations using the MutationObserver API
<script type="text/javascript">
// See MDN: https://developer.mozilla.org/en-US/docs/DOM/MutationObserver?redirectlocale=en-US&redirectslug=DOM%2FDOM_Mutation_Observers
(function(){
// select the target node
var target = document.querySelector('body');
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var i={};
// create an observer instance
var observer = new MutationObserver(function(mutations) {
@petehamilton
petehamilton / README.md
Last active March 31, 2020 18:18
Circle CI Build Status widget for Dashing (Multiple Builds)

Description

Dashing widget to show the status of builds from CircleCI. Also shows the avatar of the person who is running/breaking/passing the current build.

Usage

  • Get a Circle API Token from your Account Dashboard and set it in your environment as CIRCLE_CI_AUTH_TOKEN
  • Add the httparty to your Gemfile and run bundle install

Then:

@hrdwdmrbl
hrdwdmrbl / ability.rb
Created June 5, 2013 23:06
CanCan -- HowTo cache the ability.rb file
class Ability
include CanCan::Ability
def marshal_dump
#blocks cannot be cached
@rules.reject{|rule| rule.instance_variable_get :@block }.map{|rule| Marshal.dump(rule) }
end
def marshal_load array
#blocks cannot be cached, so blocks must be re-defined
can :read, Comment do |comment|
@jed
jed / how-to-set-up-stress-free-ssl-on-os-x.md
Last active July 10, 2024 14:35
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active May 28, 2024 17:41
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@avit
avit / lib-gem_ext-arel-predications.rb
Created September 21, 2013 01:13
Allow Ransack to include NULL values in "does not equal" searches.
module Arel
module Predications
def not_eq other
if other.is_a? Nodes::Not
Nodes::Equality.new self, other.value
else
Nodes::NotEqual.new self, other
end
end