Skip to content

Instantly share code, notes, and snippets.

View can3p's full-sized avatar

Dmitrii Petrov can3p

View GitHub Profile
#!/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")
<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>
@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()
@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 / 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: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 / gist:4046235
Created November 9, 2012 15:12
commonjs + amd wrapper
do (exports = if typeof exports == 'undefined' then undefined else exports) ->
module = ->
#example module content
_ = require 'underscore'
_([3,1,2]).sort()
return {
a: ->
b: ->
}
@can3p
can3p / gist:4055931
Created November 11, 2012 19:15
jitsu deploy
$ jitsu deploy
info: Welcome to Nodejitsu nko3-vermishel-team
info: jitsu v0.11.3, node v0.8.12
info: It worked if it ends with Nodejitsu ok
info: Executing command deploy
info: Analyzing application dependencies in node lib/server.js
info: Creating snapshot 0.0.8-6
info Uploading: [=============================] 100%
info: Updating app nko3-vermishel-team
info: Activating snapshot 0.0.8-6 for nko3-vermishel-team
@can3p
can3p / alive.vba
Created March 21, 2013 17:26
chech url in vba
Function Alive(ByVal url As String) As String
Dim result As String
Dim winHttpReq As Object
Set winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
winHttpReq.Open "GET", url, False
On Error Resume Next
winHttpReq.Send
If Err.Number = 0 Then
Function FileExists(ByVal fname As String) As String
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(fname) Then
FileExists = "1"
Else
FileExists = "0"
End If