Skip to content

Instantly share code, notes, and snippets.

View pconerly's full-sized avatar
💭
doing code archeology

Peter Conerly pconerly

💭
doing code archeology
View GitHub Profile
@pconerly
pconerly / derp.ts
Created April 20, 2021 19:40
Enforce same argument in typescript
function requireSameArgType<A>(a: A, b: A) {
return null;
}
function main() {
requireSameArgType(1, 2);
requireSameArgType('string', 'still a string');
requireSameArgType(1, 'string');
}
function requireSameObjShape<T, K extends T>(a: T, b: K) {
#pragma once
#include "defs.h"
struct StringParser {
const char *pos, *end;
char peek() { return *pos; }
@pconerly
pconerly / eip_failover.sh
Last active September 19, 2015 01:06 — forked from Ashex/eip_failover.sh
EIP failover
#!/bin/sh
# This script will monitor another HA node and take over an Elastic IP (EIP)
# if communication with the other node fails
# High Availability IP variables
# Other node's IP to ping and EIP to swap if other node goes down
HA_Node_IP=10.0.0.11
EIP=10.0.0.10
#Specify the Secondary Private IP for this node
@pconerly
pconerly / django_command.py
Last active August 29, 2015 14:20
Rolling your own localtunnel
# this file lives in /project/app/management/commands/devtunnel.py
# it just spins up a localtunnel and retries it if it fails, until it gets a key command shutdown.
# you need to define some configuartion in your settings.py: SSH_TUNNEL_USER, SSH_SERVER_IP
# This assumes you're running your website on port 8070
import sys
import time
import subprocess
from django.conf import settings
@pconerly
pconerly / record_nock_to_json_file.js
Created March 5, 2015 19:50
Record nocks to a json file
var nock = require('nock');
var low = require('lowdb');
// lowdb is a great straight-to-json minidb.
var db = low('integration_test_nock_records.json');
writeToFileLog = function(object) {
console.log("writing nock to json....");
db('records').push(object);
}
@pconerly
pconerly / info.md
Created September 17, 2014 19:29
Sublime text power-users session

Sublime text:

Plugins:

GitGutter

Languages

Preferences:

Language preferences.

import fnmatch
import glob
import os
start_dir = '.'
start_dir = '/Users/peterconerly/src/picmonkey/py/frontend/frontend/static/js/v2'
extension = '*.coffee'
for root, dirnames, filenames in os.walk(start_dir):
@pconerly
pconerly / app.py
Created May 12, 2014 17:40
Failing to run Tornado tests
#!/usr/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.web
from tornado.options import options
class FooHandler(tornado.web.RequestHandler):
def get(self):
self.write("derp")
@pconerly
pconerly / README.md
Last active November 6, 2024 10:01
python's `if __name__ == "__main__"`, but for php.
A slightly fuller example for this stackoverflow question: PHP equivalent of Python's name == “main”?

If you run php import.php the expected output is:

$ php import.php 
I am import.php
I am import.php, and I was run from the command line.
@pconerly
pconerly / fabfile.py
Created May 1, 2013 21:25
Using jinja2 with fabric
import os
from fabric.api import *
from jinja2 import Environment, FileSystemLoader
from StringIO import StringIO
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
@task
def config():
# put nginx.conf template into remote nginx folder