Skip to content

Instantly share code, notes, and snippets.

View sourcepirate's full-sized avatar
🏠
Work and pray

Sathya Narrayanan sourcepirate

🏠
Work and pray
View GitHub Profile
@sourcepirate
sourcepirate / curry.py
Created January 11, 2017 15:58
Currying
from functools import partial, wraps
def curry(f):
@wraps
def inner(*args, **kwargs):
return partial(f, *args, **kwargs)
return inner
@curry
import math
def test_propotions(height, width):
"""checking the width and height of the number"""
return height/width == math.sqrt(2)
def get_dimensions(a, b):
"""checks it"""
if a > b:
var observeDOM = (function(){
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
eventListenerSupported = window.addEventListener;
return function(obj, callback){
if( MutationObserver ){
// define a new observer
var obs = new MutationObserver(function(mutations, observer){
if( mutations[0].addedNodes.length || mutations[0].removedNodes.length )
callback();
var $j = jQuery.noConflict();
var down_x = null;
var up_x = null;
$j().ready(function(){
$j("#slider > div").mousedown(function(e){
e.preventDefault();
down_x = e.pageX;
});
$j("#slider > div").mouseup(function(e){
up_x = e.pageX;
@sourcepirate
sourcepirate / node_debian_init.sh
Created January 30, 2016 03:50 — 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
@sourcepirate
sourcepirate / astar.py
Created October 3, 2015 06:11 — forked from jamiees2/astar.py
A* Algorithm implementation in python.
# Enter your code here. Read input from STDIN. Print output to STDOUT
class Node:
def __init__(self,value,point):
self.value = value
self.point = point
self.parent = None
self.H = 0
self.G = 0
def move_cost(self,other):
return 0 if self.value == '.' else 1
@sourcepirate
sourcepirate / http.php
Last active September 18, 2015 10:52
simple http request example in php
<?php
/*
* simple HttpRequest example using PHP
* tom slankard
*/
class HttpRequest {
public $url = null;
@sourcepirate
sourcepirate / Base64.js
Last active August 29, 2015 17:34
Algorithm to convert Strings to base 64
var Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
@sourcepirate
sourcepirate / Base64.js
Created August 29, 2015 16:00
Algorithm to convert Strings to base 64
var Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function(e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
@sourcepirate
sourcepirate / parse.py
Last active August 29, 2015 14:24 — forked from kssreeram/parse.py
import sys
#
# ParserInput
#
# This class represents the input data and the current
# position in the data.
#
# Brief note about 'max_position':