Skip to content

Instantly share code, notes, and snippets.

Avatar

Steve Lacey stevelacey

View GitHub Profile
@stevelacey
stevelacey / networkchange.sh
Last active Sep 3, 2020
Sync local IP to Cloudflare DNS on MacOS network change, lets you make your own xip.io but with a static URL
View networkchange.sh
#!/bin/bash
CLOUDFLARE_API_KEY=changeme
CLOUDFLARE_DNS_RECORD=*.somewildcard.yourdomain.com
CLOUDFLARE_DNS_RECORD_ID=
CLOUDFLARE_ZONE=yourdomain.com
CLOUDFLARE_ZONE_ID=
if [[ "${CLOUDFLARE_ZONE_ID}" == "" ]]; then
CLOUDFLARE_ZONES=`curl -s "https://api.cloudflare.com/client/v4/zones" \
@stevelacey
stevelacey / routers.py
Last active Jun 13, 2020
Django REST Framework custom API root view with permissions filter
View routers.py
from collections import OrderedDict
from myproject.api.views import APIRootView
from rest_framework import permissions, routers
from rest_framework_nested.routers import NestedSimpleRouter
class Router(routers.DefaultRouter):
include_root_view = True
include_format_suffixes = False
root_view_name = 'index'
View ssl-wildcard-dev.sh
cat > openssl.cnf <<-EOF
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
CN = *.${PWD##*/}.dev
[v3_req]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
@stevelacey
stevelacey / iana-to-activerecord-bullshit-timezone-mapping.py
Last active May 8, 2020
Zendesk timezones are represented by friendly names that map to tz database names. For example, an API request returns "Eastern Time (US & Canada)" instead of "America/New_York". You can map the friendly names to the tz database names by referencing the Constants > Mapping section of the Ruby on Rails TimeZone object doc. https://developer.zende…
View iana-to-activerecord-bullshit-timezone-mapping.py
# -*- coding: utf-8 -*-
"""
Zendesk timezones are represented by friendly names that map to tz database names.
For example, an API request returns "Eastern Time (US & Canada)" instead of "America/New_York".
You can map the friendly names to the tz database names by referencing the Constants > Mapping
section of the Ruby on Rails TimeZone object doc.
https://developer.zendesk.com/rest_api/docs/core/users#time-zone
View nomadlist-bulk-import.js
var geocoder = new google.maps.Geocoder();
var trips = [
{ action: 'trip', date_start: '2000-10-21', date_end: '2000-10-29', city: 'Fuerteventura', country: 'Spain' },
{ action: 'trip', date_start: '2000-10-29', date_end: '2000-12-28', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2000-12-28', date_end: '2001-01-04', city: 'Lagos', country: 'Portugal' },
{ action: 'trip', date_start: '2001-01-04', date_end: '2001-04-08', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2001-04-08', date_end: '2001-04-15', city: 'Paphos', country: 'Cyprus' },
{ action: 'trip', date_start: '2001-04-15', date_end: '2001-08-27', city: 'Nottingham', country: 'UK' },
{ action: 'trip', date_start: '2001-08-27', date_end: '2001-08-31', city: 'Nice', country: 'France' },
@stevelacey
stevelacey / Collect recursive JSON key paths In Postgres.sql
Created Sep 10, 2015
Collect recursive JSON key paths In Postgres
View Collect recursive JSON key paths In Postgres.sql
WITH RECURSIVE doc_key_and_value_recursive(key, value) AS (
SELECT
t.key,
t.value
FROM ideas, json_each(ideas.custom) AS t
WHERE ideas.bucket_id = 889
UNION ALL
SELECT
@stevelacey
stevelacey / capistrano-postgres-db-tasks.rb
Last active Sep 18, 2015
capistrano postgres db push pull
View capistrano-postgres-db-tasks.rb
# config valid only for Capistrano 3.1
lock '3.1.0'
namespace :db do
desc "Push database"
task :push do
run_locally do
app_server = roles(:app).first
db_server = 'db.server.example.com'
user = 'simpleweb'
View keyhook.js
(function() {
var KeyHook = {
init: function(e) {
if (e.keyCode == 13) {
if (!e.target || !e.target.form) return;
var button;
if (this.isSubmitButton(e.target)) {
button = e.target;
@stevelacey
stevelacey / middleware.py
Last active Feb 13, 2017 — forked from mindlace/middleware.py
UserstampMiddleware
View middleware.py
# -*- coding: utf-8 -*-
from django.db.models import signals
from django.utils.functional import curry
from rest_framework import authentication
class UserstampMiddleware(object):
"""Add user created_by and updated_by foreign key refs to any model automatically.
Almost entirely taken from https://github.com/Atomidata/django-audit-log/blob/master/audit_log/middleware.py"""
def process_request(self, request):
View consitution.md

Organisation constitution

full legal name or any trading name

PHP South West UK

detail purpose of the account

...

country or formation

UK

You can’t perform that action at this time.