Skip to content

Instantly share code, notes, and snippets.

@jpthompson23
jpthompson23 / HTTP_header_update_decorator.py
Last active March 24, 2016 09:46
Python decorator to update the header of an HTTP response from Flask or whatever
import flask
from flask.ext.classy import FlaskView, route
from functools import wraps
def charset_utf8(viewmethod):
# Let's update the 'Content-Type' in the HTTP header to tell the browser that the data we're
# responding with has utf-8 character encoding.
@wraps(viewmethod)
def new_viewmethod(*args, **kwargs):
resp = viewmethod(*args, **kwargs)
@jpthompson23
jpthompson23 / Flask_Classy_autoregistrant_metaclass.py
Last active September 21, 2016 13:44
Create a metaclass to automatically register new views with the app in Flask-Classy
from flask import Flask, render_template
from flask.ext.classy import FlaskView, route
# Instantiate the app:
app = Flask(__name__)
# create a metaclass to automatically register views with the app
# and create the class AutoregView to use it
# ------------------------------------------------------------------------------
def Autoregistrant(app=app):
@jpthompson23
jpthompson23 / newton.cc
Last active November 26, 2020 20:46
Newton's method in C++
#include <iostream>
#include <cmath>
#include <functional>
struct NewtonSolver {
std::function<float(const float)> f;
std::function<float(const float)> fprime;
const float tol;
NewtonSolver(
float(& arg_f)(const float), float(& arg_fprime)(const float), const float arg_tol):
package local.john;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayDeque;
import java.util.Iterator;
import time
import threading
def sleep_print(n):
time.sleep(n)
print n
def thread_apply(func, item):
def run():
func(item)
@jpthompson23
jpthompson23 / scalaPractice.sc
Last active October 11, 2016 03:54
Scala Generics Worksheet
object scalaPractice {
def squareAddOne[T](x: T)
(implicit numeric: Numeric[T]): T = {
import numeric._
x*x + one
}
squareAddOne(3)