Skip to content

Instantly share code, notes, and snippets.

@rob-murray
rob-murray / do_something_form_submit.js.coffee
Last active August 29, 2015 14:06
Do something on form submit: Javascript/Coffeescript
$(document).ready ->
$('form').submit ->
$(this).find('.ajax-loader').show()
@rob-murray
rob-murray / ruby_net_http_example.rb
Created October 5, 2014 10:48
An example of using Ruby's Net::HTTP with headers
params = {
'oauth_blah' => 'value'
}
host = "https://api.example.com"
uri = URI.parse host
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new('/v1/resource')
@rob-murray
rob-murray / tweet_tag.rb
Created October 7, 2014 20:41
A new version of Jekyll Tag plugin to display oEmbed Tweets - fixed to use SSL
# A Liquid tag for Jekyll sites that allows embedding tweets using Twitter's
# oEmbed API, and showing the tweet as a blockquote for non-JavaScript enabled
# browsers and readers.
#
# Updated: fixed to use SSL for Twitter oEmbed API endpoint.
#
# Author: Scott W. Bradley / https://github.com/rob-murray/
# Source URL: https://github.com/scottwb/jekyll-tweet-tag
# New source URL: https://gist.github.com/rob-murray/ee56870e9daf4f2eb52c
#
@rob-murray
rob-murray / 1_models.rb
Last active August 29, 2015 14:07
Rails ActiveRecord #composed_of macro
# == Schema Information
#
# Table name: blocks
#
# id :integer not null, primary key
# name :string(255)
# content :text
# type :string(255)
# created_at :datetime
# updated_at :datetime
@rob-murray
rob-murray / memcached_osx.sh
Created November 2, 2014 09:49
Install and launch Memcached on OSX from Homebrew
// Install from Homebrew
$ brew install memcached
// Copy launchctl plist
$ cp /usr/local/Cellar/memcached/{version}/homebrew.mxcl.memcached.plist ~/Library/LaunchAgents/
// Launch
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
// Un-launch
@rob-murray
rob-murray / $_form_submit.coffee
Created December 5, 2014 09:30
JQuery - Handle Form Submit
$(document).ready ->
return unless $("#form_elem_id").length
$("#form_elem_id").submit (e) ->
e.preventDefault()
$form = $(this)
errors = []
$content_el = $form.find("#something")
$errors_el = $('#form_elem_id-errors')
$errors_el.empty()
@rob-murray
rob-murray / csv_parse.rb
Created January 26, 2015 16:55
Ruby example CSV parsing
require 'csv'
require 'awesome_print'
CSV.foreach('file.csv', :row_sep => :auto) do |row|
Kernel.ap "Row>>>>>>>>>>>>>>>>>>>"
Kernel.ap row
end
@rob-murray
rob-murray / async_devise_mailer.rb
Last active August 29, 2015 14:15
Sending mail using a background job. #rails #devise
##
# This override is required and acts as a proxy to Devise::Mailer but calling
# delay on sending mail to send Devise mail async.
#
class AsyncDeviseMailer < Devise::Mailer
def self.confirmation_instructions(record, token, opts = {})
new(:confirmation_instructions, record, token, opts)
end
def self.reset_password_instructions(record, token, opts = {})
@rob-murray
rob-murray / api_wrapper.rb
Created March 4, 2015 09:24
Example API wrapper with raise or suppress exception handler
module ApiWrapper
# module to handle public api to wrapper
class << self
def from_config(config = 'config') # set up config from Initializer/Config as per req.
Connection.new(config)
end
def with_errors
connector = ErrorRaisingConnector.new(from_config)
return connector unless block_given?
@rob-murray
rob-murray / null_object.rb
Created March 16, 2015 10:13
Basic Ruby Null Object
class NullObject
def method_missing(*_args, &_block)
self
end
def respond_to?(_method_name, include_private = false)
true
end
end