Skip to content

Instantly share code, notes, and snippets.

View mfenniak's full-sized avatar

Mathieu Fenniak mfenniak

View GitHub Profile
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 / 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
@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 / 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 / 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 / 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: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 / 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.