Skip to content

Instantly share code, notes, and snippets.

View wilhelm-murdoch's full-sized avatar
💀
Busy being spoopy.

Wilhelm Murdoch wilhelm-murdoch

💀
Busy being spoopy.
View GitHub Profile
@wilhelm-murdoch
wilhelm-murdoch / aggregation_test.py
Created August 18, 2013 07:52
Testing MongoDB aggregation problem. Creates 10 posters and randomly assigns them to 100 posts. Aggregation query returns mapping of poster to latest post sorted by creation date in descending order.
from pymongo import MongoClient
import datetime
import bunch
from faker import Faker
from random import choice
client = MongoClient(host="localhost", port=27017)
faker = Faker()
posters = []
@wilhelm-murdoch
wilhelm-murdoch / arthur.itermcolors
Last active September 30, 2016 21:29
My personal fish shell setup for iTerm 2 ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.16470588743686676</real>
<key>Green Component</key>
<real>0.20784313976764679</real>
@wilhelm-murdoch
wilhelm-murdoch / generate_inkwell_articles.py
Last active December 19, 2015 23:59
A python script for creating a ton of test articles for Inkwell.
import sys
import os
from random import choice
if len(sys.argv) < 2:
print 'Usage: python {} /absolute/path/to/article/directory'.format(os.path.basename(__file__))
exit()
content = """title: Pokedex for {}
summary: true
@wilhelm-murdoch
wilhelm-murdoch / gist:5909320
Created July 2, 2013 13:32
Google image chart demo...
https://chart.googleapis.com/chart?cht=bvs&chs=750x50&chd=t:0,0,0,0,0,10,50,60,80,40&chco=EBF2FF&chbh=25,1&chm=r,FFFFFF,0,-0.01,0.01,1|R,FFFFFF,0,-0.01,0.01,1
@wilhelm-murdoch
wilhelm-murdoch / redoize.py
Last active December 15, 2015 22:09
A decorator used to cache a method's output in redis.
# -*- coding: utf-8 -*-
from functools import wraps
import redis
from flask import Flask, request
from datetime import datetime
app = Flask(__name__)
# -*- coding: utf-8 -*-
#!/usr/bin/env python
"""
urlnorm.py - URL normalisation routines
urlnorm normalises a URL by;
* lowercasing the scheme and hostname
* taking out default port if present (e.g., http://www.foo.com:80/)
* collapsing the path (./, ../, etc)
* removing the last character in the hostname if it is '.'
@wilhelm-murdoch
wilhelm-murdoch / getPureRotation.js
Created December 18, 2011 05:22
A jQuery method that attempts to calculate the angle of rotation of the given HTML element.
$.fn.getPureRotation = function(element) {
var degrees = null;
$.each(['-webkit-transform', '-moz-transform', '-o-transform', '-sand-transform', '-ms-transform', 'transform'], function(index, value) {
var matrix = $(element).css(value);
if(degrees == null || Boolean(matrix)) {
var arrMatrix = matrix.match(/[\-0-9.]+/g);
if(
(parseFloat(arrMatrix[1]) == (-1 * parseFloat(arrMatrix[2]))) ||
(parseFloat(arrMatrix[3]) == parseFloat(arrMatrix[0])) ||
((parseFloat(arrMatrix[0]) * parseFloat(arrMatrix[3]) - parseFloat(arrMatrix[2]) * parseFloat(arrMatrix[1])) == 1)
@wilhelm-murdoch
wilhelm-murdoch / getChildCategories.php
Created November 17, 2011 14:03
Recursive function for Magento that provides useful information regarding a specified category and all children.
<?php
function getCategories(Mage_Catalog_Model_Category $ParentCategory) {
$return = array();
foreach(explode(',', $ParentCategory->getChildren()) as $categoryId) {
$Category = Mage::getModel('catalog/category')->load($categoryId);
$return[$categoryId] = array(
'id' => $Category->getId(),
'name' => $Category->getName(),
'slug' => $Category->getUrlKey(),
'url' => $Category->getUrl(),
@wilhelm-murdoch
wilhelm-murdoch / $.fn.disableSelection();
Created September 16, 2011 05:23
Prevents the "bubbling" effect for text selections in the DOM. For example, when you double-click a block of text on a web page and the entire block gets highlighted and selected. Yeah, this prevents that.
(function($){
$.fn.disableSelection = function() {
return this.each(function() {
$(this).attr('unselectable', 'on')
.css({
'-moz-user-select':'none',
'-webkit-user-select':'none',
'user-select':'none'
})
.each(function() {
@wilhelm-murdoch
wilhelm-murdoch / outerHtml
Created May 30, 2011 14:12
IE's 'outerHTML' method for jQuery
jQuery.fn.outerHTML = function() {
return $('<div>').append(this.eq(0).clone()).html();
};