Skip to content

Instantly share code, notes, and snippets.

View mfenniak's full-sized avatar

Mathieu Fenniak mfenniak

View GitHub Profile
@mfenniak
mfenniak / app.py
Created June 23, 2012 15:49
An extension of Flask that adds last-modified file time information to static file URLs built by url_for
import os.path
from flask import Flask
from flask.helpers import safe_join
# Injects an "mt" parameter on the URLs of static files that contains the
# last-modified time of the file. This allows the use of aggressive cache
# settings on static files, while ensuring that content changes are reflected
# immediately due to the new URLs. Note that if multiple servers have
# different mod times on files, this can cause static files to be reloaded more
# often than needed.
@mfenniak
mfenniak / gist:2978805
Created June 23, 2012 16:01
An extension of Flask that adds file hashes to static file URLs built by url_for("static"...)
import os.path
import contextlib
import hashlib
from flask import Flask
from flask.helpers import safe_join
# Injects an "h" parameter on the URLs of static files that contains a hash of
# the file. This allows the use of aggressive cache settings on static files,
# while ensuring that content changes are reflected immediately due to the
# changed URLs. Hashes are cached in-memory and only checked for updates when
@mfenniak
mfenniak / gist:3006798
Created June 27, 2012 20:56
Plugin that enables unicode decoding for PostgreSQL's CITEXT column type when using psycopg2 and SQLAlchemy
from sqlalchemy.event import listen
def register_citext_type(conn, con_record):
from psycopg2.extensions import new_type, register_type
from contextlib import closing
def cast_citext(in_str, cursor):
if in_str == None:
return None
return unicode(in_str, cursor.connection.encoding)
with closing(conn.cursor()) as c:
c.execute("SELECT pg_type.oid FROM pg_type WHERE typname = 'citext'")
@mfenniak
mfenniak / gist:3008378
Created June 28, 2012 02:27
Creates an aggregate called hstore_merge that merges PostgreSQL's HSTORE values using the concat (||) operator
CREATE OR REPLACE FUNCTION hstore_merge(left HSTORE, right HSTORE) RETURNS HSTORE AS $$
SELECT $1 || $2;
$$ LANGUAGE SQL;
CREATE AGGREGATE hstore_merge (HSTORE) (
SFUNC = hstore_merge,
STYPE = HSTORE,
INITCOND = ''
);
@mfenniak
mfenniak / SoapUtilities.cs
Created February 4, 2013 14:27
Snippet to create and read a System.ServiceModel.Channels.Message object representing a WCF operation invocation containing multiple parameters. This is how you would use DataContractSerializer to make an entire operation call, including each individual parameter, rather than just serializing one object at a time.
using System;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Text;
using System.Xml;
public static class SoapUtilities
@mfenniak
mfenniak / generate_dialogs.py
Created May 7, 2013 13:13
Script to convert a graphviz file (idempotent.dot) into an HTML + svg file with clickable nodes and edges that display data in a Bootstrap dialog. Used to generate https://mathieu.fenniak.net/idempotent-api-roadmap-prototype/, a prototype of a graph-based information delivery system. This script is a real ... efficient use of developer time. It …
import pydot
import subprocess
import sys
import re
print """<!DOCTYPE html>
<html>
<head>
<title>Idempotency Concept Roadmap Prototype</title>
<link href="https://mathieu.fenniak.net/wp-content/uploads/2013/05/bootstrap.min_.css" rel="stylesheet" media="screen">
@mfenniak
mfenniak / remote-api.hs
Created June 19, 2014 20:07
My first ugly working Haskell program, making an HTTP request w/ hard-coded JSON to retrieve data from Replicon's old RepliConnect API.
import Network.HTTP
import Network.URI
import Data.Either
data InstanceInfo =
InstanceInfo {
apiURL :: URI,
companyKey :: String,
loginName :: String,
password :: String
import Ember from 'ember';
// computedDependent is a wrapper around Ember.computed that promotes a property access pattern that
// ensures that a computed property declares its dependencies accurately.
//
// You create a computed property with computedDependent, passing in the getter function and the names
// of the dependent properties as additional arguments. The getter function will be called with a
// single object argument which has ES5 properties defined upon it matching the names of the dependent
// properties; you can then use this 'props' argument to access the dependent properties.
//
@mfenniak
mfenniak / index.js
Created June 7, 2016 13:58
Example implementation of disabling loading of a specific fortunejs relationship (fortunejs/fortune#219)
'use strict';
const fortune = require('fortune');
const http = require('http');
const JsonApiSerializer = require('fortune-json-api');
const MemoryAdapter = require('fortune/lib/adapter/adapters/memory');
const HttpSerializer = fortune.net.http.Serializer;
const store = fortune(
{
@mfenniak
mfenniak / vagrant.log
Last active August 4, 2016 13:57
vagrant debug log for hashicorp/vagrant#7682
INFO global: Vagrant version: 1.8.5
INFO global: Ruby version: 2.2.3
INFO global: RubyGems version: 2.4.5.1
INFO global: VAGRANT_EXECUTABLE="C:\\HashiCorp\\Vagrant\\embedded\\gems\\gems\\vagrant-1.8.5\\bin\\vagrant"
INFO global: VAGRANT_INSTALLER_EMBEDDED_DIR="C:\\HashiCorp\\Vagrant\\embedded"
INFO global: VAGRANT_INSTALLER_ENV="1"
INFO global: VAGRANT_INSTALLER_VERSION="2"
INFO global: VAGRANT_INTERNAL_BUNDLERIZED="1"
INFO global: VAGRANT_LOG="debug"
INFO global: VAGRANT_OLD_ENV_="ExitCode=00000001"