Skip to content

Instantly share code, notes, and snippets.

@honza
honza / strip.js
Created August 3, 2011 14:30
Strip MS Word formatting in javascript
// Source: http://www.1stclassmedia.co.uk/developers/clean-ms-word-formatting.php
function CleanWordHTML( str )
{
str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
@honza
honza / marriage.txt
Created August 4, 2011 23:03
Django symmentrical ManyToMany to self
Django
======
Person should have a ManyToMany field to 'self' through a Marriage model. The
field should be symmentrical so that both people konw they are married to each
other. The Marriage model contains information about the marriage, such as it
start, end, etc.
/----------------------\
@honza
honza / bash.sh
Created September 19, 2011 10:34
gunicorn_django
# Manually connecting to the server via ssh and executing
$ gunicorn_django -c gunicorn --daemon settings_server.py
# ... works fine.
# But running the same thing via Fabric, does not.
# Yes, I'm in the right directory and yes it's in virtualenv.
# The command succeeds, but gunicorn isn't running afterwards.
# gunicorn.py
# bind = '127.0.0.1:8888'
@honza
honza / json.js
Created September 28, 2011 18:54
Class constructors with JSON
// Photo class
// -----------
//
// Attributes:
// - filename
// - height
// - width
// - mimetype
// - filesize
@honza
honza / gist:1259853
Created October 3, 2011 18:33
Assigning callbacks to events on elements inside a class
// The current xobni way
var Photo = function() {
this.img = $('<img/>');
this.caption = $('<p/>');
};
Photo.prototype.setImgClick = function(callback) {
this.img.click(callback);
};
@honza
honza / pass.js
Created December 1, 2011 13:32
Pass by reference in Javascript
var status = {
enginesOn: true,
acOn: false
};
var toggle = function(obj, key) {
if (obj[key]) obj[key] = false;
else obj[key] = true;
};
@honza
honza / gist:1642160
Created January 19, 2012 19:51
Delegating with jQuery's this
class X
delegate: (selector, eventName, method) ->
$(el).delegate selector, eventName, ->
method @
@honza
honza / gist:1665483
Created January 23, 2012 20:52
django back and front widgets js
(function($) {
})(jQuery || django.jQuery);
@honza
honza / gist:1678053
Created January 25, 2012 19:28
numbers
expect = require 'expect.js'
formatPhoneNumber = (number) ->
length = number.length
console.log number
if number[0] is '1'
switch length
when 1
@honza
honza / qa.coffee
Created February 6, 2012 01:23
Quicksort in Haskell, Python, CoffeeScript and C
qs = (arr) ->
if arr.length <= 1
return arr
[].concat qs(i for i in arr when i < arr[0]), [arr[0]], qs(i for i in arr when i > arr[0])