Skip to content

Instantly share code, notes, and snippets.

View stevelacey's full-sized avatar
🚀
Shipping

Steve Lacey stevelacey

🚀
Shipping
View GitHub Profile
const widget = new ListWidget()
widget.backgroundColor = Color.black()
const amount = (number) => '$' + new Intl.NumberFormat().format(Math.round(number))
const text = (text, fontSize) => {
const t = widget.addText(text)
t.font = new Font('Avenir-Heavy', fontSize)
t.textColor = Color.white()
@stevelacey
stevelacey / networkchange.sh
Last active September 3, 2020 05:23
Sync local IP to Cloudflare DNS on MacOS network change, lets you make your own xip.io but with a static URL
#!/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 October 20, 2023 07:35
Django REST Framework custom API root view with permissions filter
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'
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 March 28, 2024 03:20
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…
# -*- 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
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 September 10, 2015 09:28
Collect recursive JSON key paths In Postgres
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 September 18, 2015 11:06
capistrano postgres db push pull
# 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'
@stevelacey
stevelacey / keyhook.js
Last active August 29, 2015 14:16
KeyHook
(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 February 13, 2017 19:22 — forked from mindlace/middleware.py
UserstampMiddleware
# -*- 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):