Skip to content

Instantly share code, notes, and snippets.

View WTFox's full-sized avatar

A. Fox WTFox

View GitHub Profile
@WTFox
WTFox / health.yaml
Created February 17, 2017 17:05
sample tmuxinator config ~/.tmuxinator/health.yml
# ~/.tmuxinator/health.yml
name: health
root: ~/code/health/
# Optional tmux socket
# socket_name: foo
# Runs before everything. Use it to start daemons etc.
pre:
@WTFox
WTFox / apistar-hotdog.py
Created May 22, 2017 11:13
apistar-example
from apistar import App, Include, Route, schema
from apistar.docs import docs_routes
from apistar.http import Response
from apistar.statics import static_routes
_hotdogs = ['hotdog', 'hotdogs']
class Hotdog(schema.String):

Overview

Brief description of what this PR does, and why it is needed.

Fixes #XXX

Demo

Optional. Screenshots, curl examples, etc.

class Car(models.Model):
COLOR_CHOICES = (
('RED', 'red'),
('WHITE', 'white'),
('BLUE', 'blue'),
)
color = models.CharField(max_length=5, choices=COLOR_CHOICES, default='RED')
# ...
@WTFox
WTFox / musicbox.ino
Created May 17, 2018 19:16
Music box controller
int REED_PIN = D0;
int MOTOR_PIN = D3;
int LED_PIN = D7;
int MOTOR_SPEED = 255;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(REED_PIN, INPUT_PULLUP);
pinMode(MOTOR_PIN, OUTPUT);
}
@WTFox
WTFox / cloudSettings
Last active July 5, 2018 17:21
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-07-05T17:21:35.097Z","extensionVersion":"v2.9.2"}
@WTFox
WTFox / safeget.py
Created October 22, 2015 15:29
Perfect for handling nested dictionaries where values might not exist.
def safeget(dct, *keys):
dct = dict(dct)
for key in keys:
try:
dct = dct[key]
except (KeyError, AttributeError, TypeError) as e:
return None
return dct
import logging
import time
import typing as T
from cProfile import Profile
log = logging.getLogger(__name__)
// assert fails the test if the condition is false.
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
if !condition {
_, file, line, _ := runtime.Caller(1)
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
tb.FailNow()
}
}
// ok fails the test if an err is not nil.
@WTFox
WTFox / postgres_queries_and_commands.sql
Created May 19, 2020 15:29 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'