Skip to content

Instantly share code, notes, and snippets.

View danhawkins's full-sized avatar

Danny Hawkins danhawkins

View GitHub Profile
# priv/repo/migrations/20220319222511_create_groups.exs
defmodule TestApp.Repo.Migrations.CreateGroups do
use Ecto.Migration
def change do
create table(:groups) do
add :name, :string, null: false
add :region, :string, null: false
add :score, :integer, null: false, default: 0
@danhawkins
danhawkins / test.php
Created October 12, 2021 03:28
HMAC digest encoding
$signature_from_header = file_get_contents("example-signature.txt");
$webhook_secret = file_get_contents("example-secret.txt");
$raw_data = file_get_contents("example-payload.json");
// Uses the bitmask value for json encode
// JSON_UNESCAPED_SLASHES => 64
// JSON_UNESCAPED_UNICODE => 256
$json_data = json_encode(json_decode($raw_data),320);
print($json_data);
@danhawkins
danhawkins / errors.md
Last active September 18, 2021 16:47
Error codes

Generic server

There was an unknown error that occurred on our side. Our developers have been made aware of this issue and will be working to correct it as soon as possible. If this problem persists, please contact support.

Attributes Description
http_status_code 400
human_message Sorry, we are unable to handle that request at the moment.
id 1001
key generic_server
@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"

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 / 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
@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 / 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:
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 / 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") {