Skip to content

Instantly share code, notes, and snippets.

View rjmoggach's full-sized avatar
🦄
React'ing.

Robert Moggach rjmoggach

🦄
React'ing.
View GitHub Profile
@rjmoggach
rjmoggach / pixel2hex.java
Created August 17, 2011 04:51
Pixel 2 Hex Coordinate hack
// cellRadius is the distance from center to vertex or length of an edge
// longSpan is the long side of the triangle
// shortSpan is short side
float[][] XM = new float[][] { { 1 / (2*longSpan), -1 / cellRadius }, { 1 / longSpan, 0 } };
float[][] YM = new float[][] { { 1 / (2*longSpan), 1 / cellRadius }, { -1 / (2*longSpan), 1 / cellRadius } };
HVector pixel2hex(PVector pv) {
int n;
PVector mj = floorDot(pv, matrixXM);
@rjmoggach
rjmoggach / zencode.py
Created October 25, 2012 15:35
bash command line script interface for zencoder-py
#!/usr/bin/python
import os, sys
from optparse import OptionParser
from zencoder import Zencoder
DEBUG=False
if os.environ.get('ZENCODER_API_KEY'):
ZENCODER_API_KEY=os.environ.get('ZENCODER_API_KEY')
elif DEBUG:
@rjmoggach
rjmoggach / sort
Created December 4, 2012 18:52
CLI sort a list by number of unique occurences
echo 4 10 2 38 39 4 39 4 10 4 44 4 4 38 6 38 38 6 11 32 4 11 52 14 39 \
38 38 10 40 40 4 38 38 38 | fmt -1 | sort | uniq -c | sort -nr
@rjmoggach
rjmoggach / cms_app.py
Last active December 15, 2015 06:19
I use this in a site-specific app called 'theme' to add django-wiki to django-cms painlessly. With this app activated there are two app integrations available in the pages Advanced menu ("Wiki Apphook" & "Notify Apphook") Add a new subpage, select the integration, mark the page as published and in menus and django-wiki is part of the site!
# django-wiki hook for django-cms
from django.conf.urls.defaults import patterns
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
from wiki.urls import get_pattern as get_wiki_pattern
from django_notify.urls import get_pattern as get_notify_pattern
class WikiApphook(CMSApp):
@rjmoggach
rjmoggach / font_convert.py
Created May 8, 2013 14:13
Python script to convert a hierarchy of fonts to OTF format This is useful if you have a huge collection of mac fonts that use resource forks and want cross platform fonts. Use at your own risk. It's not fully tested. Backup your originals before you run the script to be safe. It requires the fontforge python library.
#!/usr/bin/python
import os, sys, string, re, MacOS
from string import capwords
import fontforge as ff
from optparse import OptionParser
TEST = False
SKIP_FILES = ['.DS_Store', '.AppleDB', 'convert_font.log', 'Icon?']
ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@rjmoggach
rjmoggach / font_family.py
Created May 8, 2013 14:16
Python script to change the font family of individual font files. It's useful if you have multiple fonts that should be the same family but are not grouped together in GUI software.
#!/usr/bin/python
import os, sys, string, re, MacOS
from string import capwords
import fontforge as ff
from optparse import OptionParser
SKIP_FILES = ['.DS_Store', '.AppleDB', 'convert_font.log', 'Icon?']
class DirectoryWalker:
@rjmoggach
rjmoggach / responsive-margins.less
Last active August 30, 2017 00:47
Responsive Margin & Padding Shortcuts for Twitter Bootstrap Using LESS CSS
//
// Responsive Margin & Padding Shortcuts for Twitter Bootstrap 3.0
// ---------------------------------------------------------------
// This is an addition to Twitter Bootstrap that allows additional margin and padding shortcuts
// for enhanced layout control purposes. It should be included after the bootstrap.less
// import statement or precompiled as you see fit. It differs from bootstrap standards in
// that for any given screen size it predetermines the margin/padding size. All you have to
// do is specify the size you want xs,sm,md,lg, or xl. The exception is for items that you
// want to be centered using auto left/right margins. This can be device responsive by
// specifying mc-xs, mc-sm, mc-md, or mc-lg depending on when you want that behavior.
@rjmoggach
rjmoggach / PersonController.js
Created January 31, 2014 23:59
waterline issue with null foreign keys
index: function(req, res) {
Person
.find()
.populate('user')
.exec(function peopleFound(err, people) {
console.log(err);
if (err) return res.json(err, 400);
if (!people) return res.json({ error: 'No people exist.' }, 404);
res.json(people);
});
$ sudo sysctl -w net.inet.ip.forwarding=1
$ sudo natd -interface en1
$ sudo ipfw add divert natd ip from any to any via en1
@rjmoggach
rjmoggach / importSVGFilesAsLayers.js
Created May 30, 2014 07:07
Illustrator script to import a folder of SVG files into separate offset layers
// Import SVG Files as Layers - Illustrator CS3 script
// Description: Imports a folder of SVG files as named layers into a new document
// Author: Robert Moggach (rob@moggach.com)
// Version: 0.0.1 on 2014-05-29
function getFolder() {
return Folder.selectDialog('Please select the folder to be imported:', Folder('~'));
}