Skip to content

Instantly share code, notes, and snippets.

@pgjones
pgjones / .psqlrc
Created April 25, 2016 19:26
Good PSQL settings file
\set ON_ERROR_ROLLBACK interactive
\timing
@pgjones
pgjones / json_response.py
Created April 24, 2016 19:27
A replacement flask response to automatically jsonify dicts use with app.response_class = JSONResponse
from flask import jsonify, Response
class JSONResponse(Response):
@classmethod
def force_type(cls, value, environ=None):
if isinstance(value, dict):
value = jsonify(value)
return super().force_type(value, environ)
@pgjones
pgjones / pre-push
Created March 3, 2016 21:59
Pre push hook to prevent push of commits less than 30 mins old
#!/bin/bash
commit_timestamp=$(date -d @$(git log -n1 --format="%at") +%Y%m%d%H%M)
now=$(date +%s)
difference=($now - $commit_timestamp)
max=$((30 * 60))
if [ "$difference" -lt "$max" ]
then
echo "Too soon"
exit 1
@pgjones
pgjones / Dockerfile
Last active June 14, 2016 19:20
Initial docker file parts for a python3 app
FROM debian:jessie
RUN apt-get update && apt-get install -y \
python3 python3-dev \
python3-pip \
python3-virtualenv
RUN python3 -m virtualenv --python=python3 /ve
ENV PATH=/ve/bin:${PATH}
@pgjones
pgjones / json_test_client.py
Last active July 15, 2022 14:56
A replacement flask test client that allows easy JSON API testing
import json
from flask.testing import FlaskClient
from flask.wrappers import Response
class JSONResponseWrapper(Response):
"""Extends the BaseResponse to add a get_json method.
This should be used as the response wrapper in the TestClient.
@pgjones
pgjones / neteller_api_client.py
Created June 9, 2015 11:41
Example client class to transfer in and out of a Neteller wallet using the REST API
import logging
import requests
log = logging.getLogger(__name__)
# Currency without decimal places according to Neteller
NETELLER_NOT_DECIMAL = ['HUF', 'JPY']
@pgjones
pgjones / app.py
Last active January 15, 2020 15:00
flask-sockets example requires: Flask, Flask-Sockets, Flask-SocketIO
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import Flask, request, render_template_string
from flask_sockets import Sockets
import json
app = Flask(__name__)
sockets = Sockets(app)
template = """
@pgjones
pgjones / Simple.py
Last active August 29, 2015 14:14
Simple class for Andy
class Value(object):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
array = []
for index in range(0, 360):
value = Value(10 * index, 20, 30)
@pgjones
pgjones / G4OpRayleigh.cc
Last active August 29, 2015 14:05
Proposed new G4OpRayleigh process for Geant4
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
@pgjones
pgjones / PlotCAEN.cc
Last active August 29, 2015 14:04
This is a workflow to load zdab, convert to RAT::DS (root) and then in a separate script plot the results.
// To run this open ROOT and do
// .L PlotCAEN.cc+
// PlotCAEN( "output_filename.root", 10 );
// where the number is the event id you'd like to view the waveforms of
#include <RAT/DU/DSReader.hh>
#include <RAT/DS/Entry.hh>
#include <RAT/DS/Digitiser.hh>
#include <TCanvas.h>
#include <TGraph.h>