Skip to content

Instantly share code, notes, and snippets.

@jhorneman
jhorneman / jquery_error_q.js
Last active April 14, 2016 12:39
Accessing full jQuery error information when using Q
// The Q 'coming from jQuery' wiki page (https://github.com/kriskowal/q/wiki/Coming-from-jQuery) says the following:
//
// "So if you are used to writing code like
// $.ajax(...).then(function (data, status, xhr) {
// console.log(data, status, xhr);
// });
// when transitioning to Q [...] you should assume they only return a single object"
//
// That is all well and good, but doesn't address how to access the multiple parameters jQuery sends, and which
// can be important.
@jhorneman
jhorneman / problems with Flux.md
Last active August 22, 2016 02:18
How to combine the Flux pattern with large hierarchical data

How to combine the Flux pattern with large hierarchical data

I've been converting the web client part of an application I'm developing for a client from plain old JavaScript to React and Flux. (Because this is closed-source client work, I will be a bit vague about what the application is and does.)

Something about my data, my use case, and how I've implemented things, or some combination of those three, doesn't fit the Flux pattern well. So I am writing this to explain my problem and hopefully get some interesting feedback on it. (If you're reading this: thanks.)

The application

I have a Python server which talks to a PostgreSQL database and provides data in JSON format over a REST-ish API (not pure REST, more RPC-style).

@jhorneman
jhorneman / async data loading in Flux.md
Last active August 22, 2016 02:18
Thoughts on where to do async data loading in Flux

Async data loading in Flux

I've been working with Flux a lot recently, and one of the questions I've been struggling with is in which part of the Flux cycle to put my asynchronous data requests.

Here are some different opinions:

The diagram

The famous Flux diagram puts them in the action creators.

The chat example

@jhorneman
jhorneman / gist:a14e49c3a9fc8a31a257
Created August 2, 2014 17:05
Small script to check for dead links
import requests
def check_link(_url):
_url = _url.strip()
if not _url:
return
if not _url.startswith('http://'):
_url = 'http://' + _url
@jhorneman
jhorneman / timestamp_osx.cpp
Created June 29, 2014 12:41
Adaption of Edouard Alligand's portable high-resolution timestamp in C++ for OS X
// main.cpp
// timestamp_test
// Created by Jurie Horneman on 29/06/14.
#include <assert.h>
#include <iostream>
// Adapted from "A portable high-resolution timestamp in C++" by Edouard Alligand
// https://blogea.bureau14.fr/index.php/2014/06/a-portable-high-resolution-timestamp-in-c/
@jhorneman
jhorneman / rawBytesToFloat.cpp
Created June 24, 2014 12:53
rawBytesToFloat
float rawBytesToFloat(char* _buffer)
{
unsigned int rawValue = asio::detail::socket_ops::network_to_host_long(*((unsigned int*) (_buffer)));
return *(reinterpret_cast<float*>(&rawValue));
}
@jhorneman
jhorneman / subprocess_gevent_test.py
Last active August 29, 2015 14:01
Non-blocking communication with a subprocess using gevent
# -*- coding: utf-8 -*-
import sys
# Based on http://stackoverflow.com/a/4896288 - modified to use Gevent
ON_POSIX = 'posix' in sys.builtin_module_names
def enqueue_output(_output_stream, _queue):
@jhorneman
jhorneman / Logging to a web page
Created July 26, 2012 09:18
Some code snippets showing how one could send logging output to a web page in Python
# web_page_logger.py
import logging
class WebPageHandler(logging.Handler):
def __init__(self):
logging.Handler.__init__(self)
self.messages = []
def emit(self, record):
@jhorneman
jhorneman / gist:3059407
Created July 6, 2012 10:26
How to filter out common unwanted characters in Python
character_replacements = [
( u'\u2018', u"'"), # LEFT SINGLE QUOTATION MARK
( u'\u2019', u"'"), # RIGHT SINGLE QUOTATION MARK
( u'\u201c', u'"'), # LEFT DOUBLE QUOTATION MARK
( u'\u201d', u'"'), # RIGHT DOUBLE QUOTATION MARK
( u'\u201e', u'"'), # DOUBLE LOW-9 QUOTATION MARK
( u'\u2013', u'-'), # EN DASH
( u'\u2026', u'...'), # HORIZONTAL ELLIPSIS
( u'\u0152', u'OE'), # LATIN CAPITAL LIGATURE OE
( u'\u0153', u'oe') # LATIN SMALL LIGATURE OE