Skip to content

Instantly share code, notes, and snippets.

View can3p's full-sized avatar

Dmitrii Petrov can3p

View GitHub Profile
@can3p
can3p / gist:1787188
Created February 10, 2012 06:29
Parse a string serialized by jQuery.param
/**
* Converts a string that was serialized with jQuery.param back to the object.
*
* @param {String} str
*
* @return {Object}
*/
function parseParams(str) {
var obj = {}, pair;
var pairs = decodeURIComponent(str).split( "&" );
@can3p
can3p / node_debian_init.sh
Created August 27, 2011 17:42 — forked from peterhost/node_debian_init.sh
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
#! /bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
@can3p
can3p / gist:1053285
Created June 29, 2011 06:50
Translate haml file according to bemto concept
#!/usr/bin/env node
/**
* Прототип прототипа, точно работать должен только на тестовом примере
* из поста. Для дальнейшей доработки нужно будет ближе ознакомиться со
* спецификацией haml и формализовать правила по трансляции имен классов =)
*
* .b-bl1
* .b-bl2_foo
* .__el
@can3p
can3p / gist:980382
Created May 19, 2011 08:10
url parsing on coffeescript
parseUrl = ( url = location.href ) ->
params = {}
( ( parts = part.split( "=" ) ) && params[ parts[0] ] = parts[1] for part in ( url.split "?" ).pop().split "&" if url.indexOf( "?" ) != -1 ) && params || {}
$ ->
console.log parseUrl( "http://test.com/?a=b" )
console.log parseUrl( "http://test.com" )
console.log parseUrl()
<script id="tpl" type="text/x-query-tmpl">
<ul>
{{tmpl ({ checkboxes: true, items: someitems }) "#genlist" }}
{{tmpl ({ checkboxes: false, items: otheritems }) "#genlist" }}
</ul>
</script>
<script id="genlist" type="text/x-query-tmpl">
{{each (idx, item) items}}
<li>{{if selectable }}<input type="checkbox" />{{/if}}${item.title}</li>
#!/usr/bin/env python
import sys, os, math
from PIL import Image
def usage():
print ("Usage:")
print ("\tcompress input_file out_image")
print ("\tcompress -d image out_file")