Skip to content

Instantly share code, notes, and snippets.

View dotmh's full-sized avatar

Martin Haynes dotmh

View GitHub Profile
@dotmh
dotmh / alpha.jquery.js
Created June 8, 2012 08:56
A Jquery Alpha range plugin
(function($){
$.alphaRange = function(from , to , onlyLetters) {
var startLetter = from || 'A',
endLetter = to || 'Z',
start = startLetter.charCodeAt(0),
end = endLetter.charCodeAt(0),
length = end - start,
letter = 0,
@dotmh
dotmh / inspect.rb
Created June 10, 2012 06:05
A ruby hash inspector
def inspect data , depth = 0
data.each do | key , value |
if value.class == Hash
spacing = ''
depth.times { spacing << '-' }
puts spacing+' '+key.to_s
inspect value , depth+1
else
spacing = ''
@dotmh
dotmh / gist:2988172
Created June 25, 2012 11:54 — forked from sasimpson/gist:1112739
Ruby Net:HTTP chunked transfer
require 'uri'
require 'net/http'
class Chunked
def initialize(data, chunk_size)
@size = chunk_size
if data.respond_to? :read
@file = data
end
end

Implement Routing for Subdomains

Rails 3.0 introduced support for routing constrained by subdomains.

A subdomain can be specified explicitly, like this:

match '/' => 'home#index', :constraints => { :subdomain => 'www' } 

How to use a PS3 controller on Mac OS X 10.7 (Lion)

  1. Open Apple menu -> System Preferences -> Bluetooth and disable Bluetooth on Mac as well as any other nearby Macs or devices which will try to pair with and confuse the controller.

  2. Reset PS3 controller by inserting paperclip into pinhole near L2 button.

  3. Connect PS3 controller to Mac with USB cable.

  4. Enable Bluetooth.

@dotmh
dotmh / Error in log
Last active December 22, 2015 23:49
Image cropper error using carrier wave
CarrierWave::ProcessingError (Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: Command ("mogrify -crop '217x217+0+136' /var/folders/1_/fj3rk_750w32l91pxp59xz180000gn/T/mini_magick20130913-12950-ul75bn.jpg") failed: {:status_code=>1, :output=>"mogrify: invalid argument for option `'217x217+0+136'': -crop @ error/mogrify.c/MogrifyImageCommand/4227.\n"}):
@dotmh
dotmh / Gemfile
Created October 28, 2013 17:51
This is the standard Rails Gemfile , that I use for most rails projects as a starting base.
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use mysql as the database for Active Record
gem "mysql2"
# Adds foreign key support to rails Active Record
# https://github.com/matthuhiggins/foreigner
# Setting up a local solr instance on a mac
# install solr with homebrew
brew install solr
# create the base solr index directory
mkdir -p /data/solr
# make sure you can write to the solr logs
sudo chown -R `whoami` /usr/local/Cellar/solr/
@dotmh
dotmh / design_document.js
Last active August 29, 2015 14:13
design documents issue in pouchdb
function(doc) {
if ( doc.collection === "foobar") {
for(var i = 0; i < doc.belongsTo.length; ++i) {
var belongTo = doc.belongsTo[i];
if ( !!belongTo.length) {
emit(belongTo);
}
}
}
}

Keybase proof

I hereby claim:

  • I am dotmh on github.
  • I am dotmh (https://keybase.io/dotmh) on keybase.
  • I have a public key whose fingerprint is 689F 08A1 2626 DF87 EEEA 2893 823D B5B6 EE1A AB67

To claim this, I am signing this object: