Skip to content

Instantly share code, notes, and snippets.

View neilmiddleton's full-sized avatar
🏠
Working from home

Neil Middleton neilmiddleton

🏠
Working from home
View GitHub Profile
@neilmiddleton
neilmiddleton / gist:1226309
Created September 19, 2011 11:10
Silent Postgres
gem "silent-postgres"
@neilmiddleton
neilmiddleton / gist:1295384
Created October 18, 2011 13:11
Wildcard selectors in sass
To produce:
.blah[class*='span'] {
text-align: center;
}
use:
.blah
&[class*='span']
@neilmiddleton
neilmiddleton / gist:1331304
Created November 1, 2011 17:43
Adding custom assets to the precompile list
config.assets.precompile += ['admin.js']
@neilmiddleton
neilmiddleton / gist:1647768
Created January 20, 2012 15:03
Lead with Postgres
select months.month,
COALESCE(users.count,0) AS count,
lead(count,1) over (order by months) as prev_month,
(count - (lead(count,1) over (order by months)) ) as delta
from
(
SELECT generate_series(
date_trunc('year', min(created_at)),
now(),
'1 month'::interval
@neilmiddleton
neilmiddleton / gist:2598073
Created May 4, 2012 22:17
Python unique followers count calc
import sys
import tweepy
CONSUMER_SECRET = 'xx'
CONSUMER_KEY = 'xx'
# Run this code first to get your auth keys from Twitter
# auth_url = auth.get_authorization_url()
#
# print 'Please authorise: ' + auth_url
@neilmiddleton
neilmiddleton / gist:2827467
Created May 29, 2012 11:01
constant_macros
module ConstantMacros
def with_constants(constants, &block)
saved_constants = {}
constants.each do |constant, val|
saved_constants[ constant ] = Object.const_get( constant )
Kernel::silence_warnings { Object.const_set( constant, val ) }
end
begin
@neilmiddleton
neilmiddleton / gist:2841924
Created May 31, 2012 08:32
Create MEDRA database from Soc, PT and LLT
DROP TABLE IF EXISTS soc;
DROP TABLE IF EXISTS pt;
DROP TABLE IF EXISTS llt;
CREATE TABLE soc (
soc_code BIGINT constraint ix1_soc01 PRIMARY KEY,
soc_name varchar(100) constraint ix1_soc02 NOT NULL,
soc_abbrev varchar(5) NOT NULL,
soc_whoart_code varchar(7),
soc_harts_code BIGINT,
@neilmiddleton
neilmiddleton / gist:3012412
Created June 28, 2012 16:41
Use Ctrl+L to flip between absolute and relative line numbering in VIM
" use Ctrl+L to toggle the line number counting method
function! g:ToggleNuMode()
if(&rnu == 1)
set nu
else
set rnu
endif
endfunc
nnoremap <C-L> :call g:ToggleNuMode()<cr>
@neilmiddleton
neilmiddleton / gist:3157328
Created July 21, 2012 21:53
50 shades of grey
rgb(39,39,39) => #272727
rgb(40,40,40) => #282828
rgb(41,41,41) => #292929
rgb(43,43,43) => #2b2b2b
rgb(44,44,44) => #2c2c2c
rgb(46,46,46) => #2e2e2e
rgb(49,49,49) => #313131
rgb(50,50,50) => #323232
rgb(52,52,52) => #343434
rgb(53,53,53) => #353535
@neilmiddleton
neilmiddleton / gist:3811369
Created October 1, 2012 12:24
Report Mailer
@report = Reports::BusinessIntelligenceReport.new
@report.customer_id = customer_id.to_i
@report.start_date = Date.strptime(start_date, "%m/%d/%Y")
@report.end_date = Date.strptime(end_date, "%m/%d/%Y")
attachments['business_intelligence_report.csv'] = @report.to_csv
mail(to: email, subject: "Business Intelligence Report") do |format|
format.text
end