Skip to content

Instantly share code, notes, and snippets.

View dougdroper's full-sized avatar

Douglas Roper dougdroper

View GitHub Profile
@dougdroper
dougdroper / fake_state.rb
Created November 7, 2012 13:54
fake state
## -*- encoding : utf-8 -*-
require 'statsd'
Rails.logger.info "Connecting to statsd with #{AppConfig[:statsd][:host]}, #{AppConfig[:statsd][:port]}"
Statsd.logger = Rails.logger
class FakeStat
def increment(*args)
end
Interview tests.
notonthehighstreet.com is an online marketplace, here is a sample of some of
the products available on our site:
Product code | Name | Price
----------------------------------------------------------
001 | Lavender heart | £9.25
002 | Personalised cufflinks | £45.00
003 | Kids T-shirt | £19.95
@dougdroper
dougdroper / lazy_deploy
Created December 6, 2012 16:33
Lazy deploy top staging
#!/usr/bin/env ruby
staging_number = ARGV[0].chomp
branch = (ARGV[1] || `git rev-parse --abbrev-ref HEAD`).chomp
remote_revision = (`ssh staging#{staging_number}.noths.com 'cat /var/sites/noths/staging/current/REVISION'`).chomp
current_revision = (`git log #{branch} -1 --pretty=format:'%H'`).chomp
if remote_revision == current_revision
puts "latest build already deployed"
else
h,m="9:11".split(':')
h = h.to_i % 12
m = m.to_i/5
spaces = [8,4,7]
numbers = [0,11,1]
nl = [1,0,2,]
puts spaces.map{|s|" "*s}.zip(numbers,nl.map{|s|"\n"*s}).flatten.join
a=" 0\n 11 1\n\n 10 2\n\n9 3\n\n 8 4\n\n 7 5\n 6\n"
puts a.sub("#{h}", 'h').sub(m.to_s, 'm').gsub(/\d+/, 'o')
@dougdroper
dougdroper / encode
Created January 18, 2013 10:16
Add # -*- encoding : utf-8 -*- to top of file with a space underneath
# -*- encoding : utf-8 -*-
# A simple library to prepend magic comments for encoding to multiple ".rb" files
module AddMagicComment
# Options :
# 1 : Encoding
# 2 : Path
# TODO : check that the encoding specified is a valid encoding
@dougdroper
dougdroper / README.md
Last active December 11, 2015 07:28
Update dependencies of engines

Update Dependencies Micro Gem

Updates a Gemfile of a dependent library from the gemfile.lock of an independent project.

Prints a new Gemfile with the gem versions matched to the independent gemfile.lock

 $ update_dependencies path_to_dependent_gemfile
@dougdroper
dougdroper / README.md
Last active December 11, 2015 17:18
CodeGolf

Remove the duplication in partner.rb and phone_number.rb without changing partner_spec.rb

@dougdroper
dougdroper / quick_routes.rb
Last active December 13, 2015 20:58
My Routing demo
require 'rails/application/route_inspector'
class QuickRoutes
def all
all_routes = Rails.application.routes.routes
inspector = Rails::Application::RouteInspector.new
[200, {}, [inspector.format(all_routes, ENV['CONTROLLER']).join "\n"]]
end
end
@dougdroper
dougdroper / ZeroClipboard.min.js
Last active December 13, 2015 21:58
chrome extention
/*!
* zeroclipboard
* The Zero Clipboard library provides an easy way to copy text to the clipboard using an invisible Adobe Flash movie, and a JavaScript interface.
* Copyright 2012 Jon Rohan, James M. Greene, .
* Released under the MIT license
* http://jonrohan.github.com/ZeroClipboard/
* v1.1.7
*/(function(){"use strict";var a=function(a,b){var c=a.style[b];a.currentStyle?c=a.currentStyle[b]:window.getComputedStyle&&(c=document.defaultView.getComputedStyle(a,null).getPropertyValue(b));if(c=="auto"&&b=="cursor"){var d=["a"];for(var e=0;e<d.length;e++)if(a.tagName.toLowerCase()==d[e])return"pointer"}return c},b=function(a){if(!l.prototype._singleton)return;a||(a=window.event);var b;this!==window?b=this:a.target?b=a.target:a.srcElement&&(b=a.srcElement),l.prototype._singleton.setCurrent(b)},c=function(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent&&a.attachEvent("on"+b,c)},d=function(a,b,c){a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent&&a.detachEvent("on"+b,c)},e
require 'csv'
class Tree
def initialize(employees)
@managers = employees.group_by {|e| e["Manager"] }
@employee_names = employees.map {|e| e["Employee Name"]}
(@managers.keys.compact - @employee_names).each do |name|
@managers[nil] << {"Employee Name" => name}
end
end