Skip to content

Instantly share code, notes, and snippets.

View mcs07's full-sized avatar

Matt Swain mcs07

View GitHub Profile
@merlinmann
merlinmann / Official Cursor-Resting Area.txt
Last active October 8, 2023 20:57
Paste this into your Google Doc for a place to store your cursor.
⌨️ Official Cursor-Resting Area:
╭―――――――╮
│ >_< │
╰―――――――╯
@jgillman
jgillman / restore.sh
Last active March 8, 2024 17:51
pg_restore a local db dump into Docker
# Assumes the database container is named 'db'
DOCKER_DB_NAME="$(docker-compose ps -q db)"
DB_HOSTNAME=db
DB_USER=postgres
LOCAL_DUMP_PATH="path/to/local.dump"
docker-compose up -d db
docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}"
docker-compose stop db
@mattupstate
mattupstate / example.py
Created February 5, 2015 03:37
JSON Patch SQLAlchemy models w/ Flask
from dictalchemy import make_class_dictable
from flask import Flask, request, jsonify, json
from flask_sqlalchemy import SQLAlchemy
from jsonpatch import JsonPatch, JsonPatchException
app = Flask(__name__)
app.debug = True
db = SQLAlchemy(app)
make_class_dictable(db.Model)
@iximiuz
iximiuz / flask_static_files_cache_invalidator.py
Last active October 28, 2019 18:56
Flask: add static file's cache invalidator param to URLs generated by url_for(). Blueprints aware.
""" Inspired by http://flask.pocoo.org/snippets/40/ """
app = Flask(__name__)
@app.url_defaults
def hashed_url_for_static_file(endpoint, values):
if 'static' == endpoint or endpoint.endswith('.static'):
filename = values.get('filename')
if filename:
if '.' in endpoint: # has higher priority
@mcs07
mcs07 / cinema.scpt
Created April 6, 2014 11:40
Parse booking confirmation emails from Cinema and add Calendar event.
-- Parse booking confirmation emails from Cinema and add Calendar event
-- Author: Matt Swain <m.swain@me.com>, Version 1.0, License: MIT
-- Triggered by Mail rule.
using terms from application "Mail"
on perform mail action with messages msgs for rule theRule
tell application "Mail"
repeat with msg in msgs
try
set msgcontent to content of msg
@mcs07
mcs07 / tautomer.py
Created April 3, 2014 15:20
Rough first go at tautomer enumeration and canonicalization using RDKit in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import copy
from itertools import tee, izip
import logging
from rdkit import Chem
from rdkit.Chem.rdchem import BondType, BondStereo, BondDir
__author__ = 'Matt Swain'
@cliftonlabrum
cliftonlabrum / gist:4589476
Created January 21, 2013 21:15
Change the Host Name on an Ubuntu server (Digital Ocean)
1. Rename the host in the web panel
2. Edit /etc/hostname
3. Edit /etc/hosts
4. Reboot
@mcs07
mcs07 / backup_db.py
Last active August 14, 2019 20:50
Simple versioned backups for MongoDB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Save versioned backups of collections in MongoDB. Quick and dirty. """
import datetime
import shutil
import os
import subprocess
import zipfile
@lsauer
lsauer / InChi.js
Created October 25, 2011 14:13
Regular Expressions for validating SMILES, InChi, InChiKey
// International Chemical Identifier Regex, by lo sauer - lsauer.com
// Morphine InchI:
var x="InChI=1S/C17H19NO3/c1-18-7-6-17-10-3-5-13(20)16(17)21-15-12(19)4-2-9(14(15)17)8-11(10)18/h2-5,10-11,13,16,19-20H,6-8H2,1H3/t10-,11+,13-,16-,17-/m0/s1"
// applying an organic character-subset
// we could check for the length property, but in case of 0 matches 'null' is returned -> hence !!.. \ generally equal to Boolean(..)
!!x.trim().match(/^((InChI=)?[^J][0-9BCOHNSOPrIFla+\-\(\)\\\/,pqbtmsih]{6,})$/ig)
>true
//generic:
x.trim().match(/^((InChI=)?[^J][0-9a-z+\-\(\)\\\/,]+)$/ig)