Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
mjumbewu / handlebars-formatTextForHTML.coffee
Last active December 19, 2015 16:49 — forked from arbales/handlebars-formatTextForHTML.coffee
Now matches things like "I got this from http://github.com/, and it's great!" as well. The trailing comma would throw it off before.
LINK_DETECTION_REGEX = /(([a-z]+:\/\/)?(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?).?(\s+|$)/gi
EMOJI_DIRECTORY = "/path/to/assets/emoji/20x20"
# Handlebars is presumed, but you could swap out
ESCAPE_EXPRESSION_FUNCTION = Handlebars.Utils.escapeExpression
MARKSAFE_FUNCTION = (str) -> new Handlebars.SafeString(str)
# Emoji unicode chars become images.
@mjumbewu
mjumbewu / gist:5923624
Last active December 19, 2015 08:09 — forked from fkh/gist:5923372
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from unittest import TestCase, main
from functools import wraps
from os import environ
# ============================================================
# Helper functions -- skip these and go to the tests...
# ============================================================
@mjumbewu
mjumbewu / Complex.js
Last active December 15, 2015 21:48 — forked from dsamarin/Complex.js
var Complex = function(real, imag) {
if (!(this instanceof Complex)) {
return new Complex (real, imag);
}
if (typeof real === "string" && imag == null) {
return Complex.parse (real);
}
this.real = Number(real) || 0;
@mjumbewu
mjumbewu / find_legistar.py
Created February 27, 2013 18:39
A scraper to collect Legistar subdomain names from Google
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
from requests import get
import re
import time
pattern = re.compile(r'(\w+)\.legistar\.com')
@mjumbewu
mjumbewu / gist:4667649
Last active February 5, 2024 17:59
Synaptic TouchPad properties on a Dell XPS 13
mjumbewu@mjumbewu-xps ~
$ uname -a
Linux mjumbewu-xps 3.5.0-22-generic #34+kamal11~DellXPS-Ubuntu SMP Fri Jan 11 09:12:57 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
mjumbewu@mjumbewu-xps ~
$ xinput list-props 12
Device 'CyPS/2 Cypress Trackpad':
Device Enabled (132): 1
Coordinate Transformation Matrix (134): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Accel Profile (255): 1
@mjumbewu
mjumbewu / renderers.py
Last active November 28, 2019 09:19
A Django REST Framework renderer which renders data from DRF serializers into CSV. The underlying functions will render any hierarchy of Python primitive containers to CSV.
import csv
from collections import defaultdict
from rest_framework.renderers import *
from StringIO import StringIO
class CSVRenderer(BaseRenderer):
"""
Renderer which serializes to CSV
"""
#!/usr/bin/env python
import os
from django.core.management import setup_environ
import settings
setup_environ(settings)
from django.conf import settings
from django.contrib.gis.gdal import CoordTransform, DataSource, OGRGeometry, OGRGeomType
from django.core.management.base import BaseCommand
@mjumbewu
mjumbewu / gist:3677442
Created September 8, 2012 17:20 — forked from ptone/gist:3490967
Using djangorestframework2 to get JSON given just a resource outside of a view
from djangorestframework.renderers import JSONRenderer
from colorpicks.serializer import ColorSerializer
# NOTE: Resources are nominally much less present in the
# restframework2 branch. You use Serializers directly
# to achieve the same thing.
obj = ...
serializer = ColorSerializer(instance=obj)
data = serializer.data
@mjumbewu
mjumbewu / gist:3651921
Created September 6, 2012 06:05
An example of how to do URL resolution with django-jstemplates
# chadmasso has an interesting solution to using Django template tags in your
# Handlebars JS templates: precompile the template to Handlebars JS code, and
# then run the template through Django's template renderer.
#
# https://github.com/chadmasso/pencilthin
#
# Below are two possibilities for how a similar thing would be accomplished in
# django-jstemplate.
#
# 1) PREPROCESSOR(S)
@mjumbewu
mjumbewu / gist:3614854
Created September 3, 2012 23:35
Synaptics TouchPad properties on a System76 Lemur
mjumbewu@lemur:~$ uname -a
Linux lemur 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
mjumbewu@lemur:~$ xinput list-props 12
Device 'SynPS/2 Synaptics TouchPad':
Device Enabled (132): 1
Coordinate Transformation Matrix (134): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
Device Accel Profile (254): 1
Device Accel Constant Deceleration (255): 2.500000
Device Accel Adaptive Deceleration (256): 1.000000
Device Accel Velocity Scaling (257): 12.500000