Skip to content

Instantly share code, notes, and snippets.

@DanKnox
DanKnox / model_extensions.rb
Created March 10, 2012 21:19
RestClient Model Extensions
module ModelExtensions
def self.included(base_class)
base_class.send(:include,ActiveModel::Serializers::JSON)
base_class.send(:extend,ActiveModel::Naming)
base_class.send(:extend,ActiveModel::Translation)
base_class.send(:include,ActiveModel::AttributeMethods)
base_class.send(:include,ActiveModel::Validations)
base_class.send(:include,ActiveModel::Conversion)
base_class.send(:validate,:check_base_errors)
@DanKnox
DanKnox / mock_red_client.rb
Created March 23, 2012 20:01
Mocked Savon Client for testing ReD web service
class MockRedClient
attr_accessor :original_self, :soap
def request(*args,&block)
self.soap = SoapMock.new
builder = evaluate(&block) if block
MockRedResponse.new
end
def evaluate(&block)
self.original_self = eval "self", block.binding
instance_eval &block
@DanKnox
DanKnox / rails_config.rb
Created March 26, 2012 08:15
Async Rails Config
bechmark with apache bench:
ab -c 10 -n 20 http://127.0.0.1:8090/chat
install async active record mysql adapater
git clone git://github.com/igrigorik/em-mysqlplus.git
git checkout activerecord
rake install
# database.yml
development:
@DanKnox
DanKnox / array_iteration.rb
Created August 2, 2012 02:12
Array iteration interview question
def add1(arr, val, n)
stop = arr.length - 1
count = 0
(0..stop).each do |i|
index = n < 0 ? stop - i : i
if arr[index] == val
arr[index] += 1
@DanKnox
DanKnox / .vimrc
Created October 8, 2012 05:51
Vim customizations
""
"" Customisations
""
:set guifont=Consolas:h16
map <C-l> :tabn<CR>
map <C-h> :tabp<CR>
map <C-n> :tabnew<CR>
"" in .gvimrc.after
color github
@DanKnox
DanKnox / sample_controller.rb
Created November 11, 2012 00:35
Mass assignment error with has_and_belongs_to_many
# Option 1
# Explicitly assign it to avoid the mass assignment error.
def create
user_ids = params[:project].delete(:user_ids)
@project = Project.new(params[:project])
@project.user_ids = user_ids
if @project.save
flash[:success] = "Project successfully created"
redirect_to project_overview_url(@project.slug)
else
@DanKnox
DanKnox / git-workflow.md
Last active September 5, 2017 22:46
Basic GIT workflow tutorial.

Git Workflow Overview

There is an awesome online book freely available at git-scm.com. It is one of the best resources for learning git that I have come across.

If you don't have time to read the whole ebook, I have included almost everything you need to know to work with git on a daily basis below.

Standard Git Workflow

  1. Clone the remote repository to your local machine
$.fn.serializeObject = ->
json = {}
push_counters = {}
patterns =
validate : /^[a-zA-Z][a-zA-Z0-9_]*(?:\[(?:\d*|[a-zA-Z0-9_]+)\])*$/,
key : /[a-zA-Z0-9_]+|(?=\[\])/g,
push : /^$/,
fixed : /^\d+$/,
named : /^[a-zA-Z0-9_]+$/
require "ostruct"
module HL7ClientInterface
class Config::FileMissing < Errno::ENOENT; end
def self.config
@config ||= load_configuration
end
<cfscript>
QueueName = "QTransactions";
durable = true;
loadPaths = arrayNew(1);
loadPaths[1] = expandPath("lib/rabbitmq-java-client-bin-2.8.4/rabbitmq-client.jar");
// load jars
javaLoader = createObject("component", "lib.javaloader.JavaLoader").init(loadPaths);