Skip to content

Instantly share code, notes, and snippets.

View stevelacey's full-sized avatar
🚀
Shipping

Steve Lacey stevelacey

🚀
Shipping
View GitHub Profile
@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
@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'
@stevelacey
stevelacey / counties.php
Created April 18, 2012 08:45
UK Counties Array
<?php
// Source: http://www.carronmedia.com/uk-postal-counties-list
array(
'England' => array(
'Avon',
'Bedfordshire',
'Berkshire',
'Buckinghamshire',
@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 / PHP: Simple HTML Table Scrape
Created October 29, 2010 21:46
PHP: Simple HTML Table Scrape
<?php
$doc = new DOMDocument();
// It's rare you'll have valid XHTML, suppress any errors- it'll do its best.
@$doc->loadhtml($string);
$xpath = new DOMXPath($doc);
// Modify the XPath query to match the content
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 / 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):
@stevelacey
stevelacey / .htaccess
Created January 9, 2013 17:27
WordPress 8==> Symfony2
# web/blog/.htaccess (wordpress core resides in web/blog/wordpress)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
# Redirect wordpress dir
RewriteRule ^wordpress/?$ . [R=301,L]
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