Skip to content

Instantly share code, notes, and snippets.

View gmcnaughton's full-sized avatar

Gordon McNaughton gmcnaughton

View GitHub Profile
require 'uri'
require 'net/http'
require 'openssl'
class UrlResolver
def self.resolve(uri_str, agent = 'curl/7.43.0', max_attempts = 10, timeout = 10)
attempts = 0
cookie = nil
until attempts >= max_attempts
@joepie91
joepie91 / delay-promise.js
Last active July 29, 2022 20:02
ES6 Promise.delay
module.exports = function(duration) {
return function(){
return new Promise(function(resolve, reject){
setTimeout(function(){
resolve();
}, duration)
});
};
};
@brycesenz
brycesenz / customer_serializer.rb
Last active October 22, 2020 07:42
Rspec tests & helpers for ActiveModel::Serializers
# app/serializers/customer_serializer_spec.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :customer_number, :email, :username
def customer_number
object.account_number
end
def merchant_id
@bigfive
bigfive / example_mailer_spec.rb
Created January 7, 2014 08:14
ActionMailer RSpec helpers. Makes mailer test more similar to controller tests in that you can test that instance variables are assigned for rendering
require "spec_helper"
describe ExampleMailer do
describe :new_user do
let(:user) { FactoryGirl.create :user }
it "sends to the correct addresses" do
# :mail is similar to the controller specs 'get', 'post' etc methods
mail :new_user, user
@trinitronx
trinitronx / truecrypt_fix.bash
Last active April 27, 2023 15:45 — forked from jimjh/truecrypt_fix.bash
Fixes annoying brew doctor messages caused by Truecrypt
#!/bin/bash
libs=( "/usr/local/lib/libmacfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i64.2.dylib" \
"/usr/local/lib/libmacfuse_i64.2.dylib" \
"/usr/local/lib/libosxfuse_i32.la" \
"/usr/local/lib/libosxfuse_i64.la" \
"/usr/local/lib/pkgconfig/osxfuse.pc" )
@zerolab
zerolab / gist:1633661
Created January 18, 2012 15:52
Convert smart quotes with regular ones (and vice-versa)
<?php
//Quotes: Replace smart double quotes with straight double quotes.
//ANSI version for use with 8-bit regex engines and the Windows code page 1252.
preg_replace('[\x84\x93\x94]', '"', $text);
//Quotes: Replace smart double quotes with straight double quotes.
//Unicode version for use with Unicode regex engines.
preg_replace('[\u201C\u201D\u201E\u201F\u2033\u2036]', '"', $text);
@nruth
nruth / gist:1049494
Created June 27, 2011 18:50
testing devise password recovery email with email_spec and capybara / rspec request spec
require 'spec_helper'
describe "member password recovery" do
# As a member who forgot my password
# I want to recover my site access easily
#
attr_accessor :current_email_address
specify "email recovery of a new password" do
member = make_activated_member