Skip to content

Instantly share code, notes, and snippets.

View pezholio's full-sized avatar

Stuart Harrison pezholio

  • Birmingham / London
View GitHub Profile
@pezholio
pezholio / CreateCouncils.rb
Created January 27, 2012 16:24
CreateCouncils
class CreateCouncils < ActiveRecord::Migration
def change
create_table :councils do |t|
t.name :string
t.code :string
t.address :text
t.tel :text
t.fax :text
t.email :text
t.logo :text
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
== CreateCouncils: migrating =================================================
-- create_table(:councils)
@pezholio
pezholio / edubasekml.php
Created March 23, 2012 11:08
Parsing SPARQL results form eductation.data.gov.uk into KML
<h1>KML Generator for Edubase data</h1>
<?php
require_once("xmlparse.php");
if (!$_POST) {
$query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?authority ?label
WHERE {
?authority
@pezholio
pezholio / FFS
Created April 4, 2012 15:22
FFS
...
# For crying out loud
gem 'rake', '0.9.2.2'
...
@pezholio
pezholio / README.markdown
Created April 30, 2012 10:00
jq-wysihat fixes for IE

jq-wysihat is a great tool for wysiwyg if you want to sidestep ugly wysiwyg editors and roll your own. Unfortunately in my experience it wasn't working in IE.

After some fiddling, I managed to get it to work by removing the IE range stuff and including selection.js instead. It now works like a charm!

@pezholio
pezholio / app.rb
Created July 23, 2012 13:17
Mongomapper Geo maxDistance problems
get "/search" do
require 'mapit'
date_from = Date.to_mongo(Date.parse(params[:date_from])) rescue nil
date_to = Date.to_mongo(Date.parse(params[:date_to])) rescue Date.to_mongo(Date.today)
if params[:postcode] != ""
mapit = Mapit.GetPostcode(params[:postcode])
applications = Application.where(:latlng => {'$near' => [mapit["lat"], mapit["lng"]], '$maxDistance' => params[:within].to_i}, :refval => /#{params[:refval]}/i, :address => /#{params[:address]}/i)
else
@pezholio
pezholio / deploy.rb
Created July 25, 2012 16:58
Capistrano deploy recipe for Padrino and Passenger with symlinked database.rb and Github hosting
set :domain, "licensing.lichfield-001.vm.brightbox.net"
set :application, "licensing"
set :deploy_to, "/home/rails/#{application}"
set :user, "rails"
set :use_sudo, false
ssh_options[:forward_agent] = true
set :scm, :git
@pezholio
pezholio / app.rb
Created August 17, 2012 13:32
More Mongomapper Geo problems
mapit = Mapit.GetPostcode(params[:postcode])
EARTH_RADIUS_M = 3959
query[:latlng] = {'$nearSphere' => [mapit["lat"], mapit["lng"]], '$maxDistance' => Float(params[:within].to_i) / EARTH_RADIUS_M }
applications = Application.where(query)
@applications = applications.paginate({:order => :receiveddate.desc, :per_page=> 10, :page => params[:page]})
@pezholio
pezholio / tweetshot.js
Created August 29, 2012 20:31
Take a screenshot of any tweet using Casper.js
var url = phantom.casperArgs.args[0]
var output = phantom.casperArgs.args[0]
var casper = require('casper').create({
pageSettings : {
userAgent : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11'
}
});
casper.start(url, function() {
@pezholio
pezholio / jsonify_padrino.rb
Created September 21, 2012 10:01
Getting Jsonify templates working in Sinatra / Padrino
# Goes in app/helpers/jsonify_padrino.rb
require 'sinatra/base'
require 'jsonify/tilt'
class JsonifySinatra < Sinatra::Base
helpers do
def jsonify(*args) render(:jsonify, *args) end
end
end