Skip to content

Instantly share code, notes, and snippets.

View schinckel's full-sized avatar

Matthew Schinckel schinckel

View GitHub Profile
@schinckel
schinckel / jekyllmarkdown.rb
Created January 9, 2012 14:26
Jekyll renderer for Marked.app
#!/usr/bin/ruby
# Github-flavored markdown to HTML, in a command-line util.
#
# $ cat README.md | ./ghmarkdown.rb
#
# Notes:
#
# You will need to install Pygments for syntax coloring
#
# $ pip install pygments
@schinckel
schinckel / LICENSE
Last active December 13, 2015 22:30
Copyright (c) 2012, Matthew Schinckel.
All rights reserved.
Based on an algorithm at http://jsres.blogspot.com.au/2008/01/convert-hsv-to-rgb-equivalent.html
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
class MyModel(models.Model):
...
def save(self, *args, **kwargs):
if self.pk:
old_version = self.__class__.objects.get(pk=self.pk)
# Now we have self and old_version, which are different
# instances of the same object.
if old_version.foo_field != self.foo_field:
# foo_field is changed, do stuff.
super(MyModel, self).save(*args, **kwargs)
@schinckel
schinckel / file.plist
Created January 11, 2012 10:19
Jekyll Syntax Grammar for TextMate
{ patterns = (
{ begin = '(---[ ]*\n)';
end = '(---[ ]*\n)';
name = 'source.yaml.header.markdown.jekyll';
patterns = ( { include = 'source.yaml'; } );
},
{ begin = '\{% +highlight +(js)( +linenos)? +%\}';
end = '\{% +endhighlight +%\}\n';
name = 'source.$1.embedded.html.markdown';
patterns = ( { include = 'source.js'; } );
@schinckel
schinckel / jquery.couch.longpoll.js
Created January 22, 2012 11:29
Long-polling handler for CouchDB
/*
# jquery.couch.longpoll.js #
A handler that can be used to listen to changes from a CouchDB database,
using long-polling.
This seemed to be a bit simpler than using continuous polling, which I
was unable to get working with jQuery.
@schinckel
schinckel / test_ouput
Created March 21, 2012 01:08 — forked from chronossc/test_ouput
Tests with models.
(github_projects_2)felipe@felipe-G51JX:~/projects/github_projects_2/clones/django-object-config/sample_project$ m test object_config --failfast --noinput
Creating test database for alias 'default'...
E
======================================================================
ERROR: test_option_create_many (object_config.tests.OptionsTest)
Test many items creation
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/felipe/projects/github_projects_2/clones/django-object-config/sample_project/object_config/tests.py", line 27, in setUp
self.model = MyModel.objects.create(name='test 1')
@schinckel
schinckel / increment_tcx_dates.py
Created May 22, 2012 12:37
Increment all of the dates within a TCX file by a certain amount.
import re
import datetime
time_re = re.compile('(?P<dt>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})')
offset = datetime.timedelta(minutes=5,seconds=1)
for line in lines:
if time_re.search(line):
time = datetime.datetime.strptime(time_re.search(line).groupdict()['dt'], "%Y-%m-%dT%H:%M:%S")
time = time + offset
@schinckel
schinckel / selectable.js
Created April 2, 2013 11:39
Knockout extension: selectable observableArray
/*
Provide an observableArray with some smarts related to selection
of an item, or items within it.
If 'multiple' is passed in, then it is a multiply selectable
array, and has two new attributes: ``selectedItems`` and ``selectedIndexes``.
If 'multiple' is not passed in, then it new attributes of
``selectedItem`` and ``selectedIndex`` are created.
from django.views.generic.base import View
def get_class(func):
if not getattr(func, 'func_closure', None):
return
for closure in func.func_closure:
contents = closure.cell_contents
if not contents:
@schinckel
schinckel / install.sh
Last active August 9, 2017 18:01 — forked from bradrydzewski/install.sh
Drone.io Install Postgres9.4
#!/bin/bash
# remove existing 9.3 installation
sudo /etc/init.d/postgresql stop
sudo apt-get --force-yes -fuy remove --purge postgresql postgresql-9.1 postgresql-client
# install 9.4
sudo apt-get install python-software-properties
sudo add-apt-repository 'deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main 9.4'
sudo apt-get update