Skip to content

Instantly share code, notes, and snippets.

View danhawkins's full-sized avatar

Danny Hawkins danhawkins

View GitHub Profile
def resolve_postcode_position(code)
cache_key = "postcode:geo:#{code.gsub(' ','')}"
coords = Rails.cache.fetch(cache_key) do
postcode_uri = URI.encode "https://maps.googleapis.com/maps/api/geocode/json?address=#{code},UK&sensor=false&key=#{CONFIG[:google][:api_key]}"
response = HTTParty.get(postcode_uri)
begin
response['results'].first['geometry']['location']
rescue
false
@danhawkins
danhawkins / compare.rb
Created May 14, 2014 20:35
Compare Script
matched_in_staging = 0
matched_in_files = 0
unmatched = []
total = 0
Dir['prod/decision/doc_file/**/*.doc'].each do |file|
total += 1
staging_check_path = file.gsub('prod/','staging/')
if File.exists?(staging_check_path)
matched_in_staging += 1
@danhawkins
danhawkins / gist:405e1dc3fa22ef4b3a2c
Created November 19, 2015 12:46
Angular watch snipped
window.countWatchers = function () {
var root = angular.element(document.getElementsByTagName('body'));
var watchers = [];
var f = function (element) {
angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) {
if (element.data() && element.data().hasOwnProperty(scopeProperty)) {
angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) {
watchers.push(watcher);
@danhawkins
danhawkins / signal_catching.rb
Created April 29, 2016 19:18 — forked from sauloperez/signal_catching.rb
How to catch SIGINT and SIGTERM signals in Ruby
# Signal catching
def shut_down
puts "\nShutting down gracefully..."
sleep 1
end
puts "I have PID #{Process.pid}"
# Trap ^C
Signal.trap("INT") {
Job.current.map{|j| j.update(courier_id: nil, state:'pending_assignment', submitted_at: Time.now() + rand(1..100).minutes, pending_confirmation_courier_id: nil)}
Job::Pickup.joins(:job).merge(Job.current).update_all(state: 'pending', ordering_state: 'inactive')
User.courier.working_or_active.map{|c| TrackingLocation::RedisPublisher.new(c.last_location).call}
@danhawkins
danhawkins / README.md
Created December 20, 2016 19:14 — forked from davejlong/README.md
Forecast widget and job for Kitto

Forecast Widget and Job Powered By Forecast.io

This package includes a job to pull forecasts from the Forecast.io API and a widget to display the forecast information.

Install

  1. Install into your dashboard with mix kitto.install --gist 229b76b15eae45ee9f5cc1e5d62a40eb
  2. Register for a DarkSky API key and set it into your applications environment in config/config.exs:
@danhawkins
danhawkins / index.js
Created November 27, 2020 17:40
Example cloud functions
exports.helloAgainWorld = (req, res) => {
res.status(200).send({ message: 'Hello Again World' })
}
@danhawkins
danhawkins / cloudbuild.yaml
Created November 27, 2020 18:08
Example cloudbuild.yaml
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args:
- functions
- deploy
- hello-again-world
- --source=https://source.developers.google.com/projects/danny-playground/repos/hello-again-world
- --trigger-http
- --region=europe-west1
- --runtime=nodejs12

All of the SQL queries below are wrapping in SQL views stored on BigQuery, they may use other tables or views undernear, but this is what we connect to in Tableau data source

Days

The raw query is:

SELECT 
  date
FROM
  UNNEST(GENERATE_DATE_ARRAY('2017-01-01','2022-01-01')) as date
@danhawkins
danhawkins / rules.html
Created April 17, 2021 16:45
season-11-rules-content
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
href="//vrmasterleague.com/css/bootstrap.min.css"
rel="stylesheet"
type="text/css"