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
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();
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:
@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 requests
from multiprocessing import Queue, Process, Pool
from peewee import *
db = SqliteDatabase('github.db')
class Github(Model):
name = CharField(unique=True)
no_repos = IntegerField()
no_follower = IntegerField()
@sourcepirate
sourcepirate / grad.py
Created May 15, 2017 12:12
gradient descent algorithm
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
def hypothesis(x, theta):
"""function"""
return x.dot(theta).sum()
def compute_cost(X, Y, theta):
"""errors"""
{"posts": {"children": [1, 2,3, 4], "new": {"hello": "world"}}}
@sourcepirate
sourcepirate / scrapper.py
Last active July 1, 2017 17:56
Distibuted crawler in python
import queue
from multiprocessing.managers import SyncManager
from multiprocessing import Process, RLock
from bs4 import BeautifulSoup
from urllib import request
from urllib.parse import urlparse, urljoin
from multiprocessing.managers import MakeProxyType
BaseSetProxy = MakeProxyType('BaseSetProxy', ('__and__', '__contains__', '__iand__', '__ior__',
'__isub__', '__ixor__', '__len__', '__or__', '__rand__', '__ror__', '__rsub__',
@sourcepirate
sourcepirate / amazon-river-wave.py
Created July 2, 2017 08:13
Scrapping all amazon laptops data.
"""scrape amazon laptop and desktop prices"""
import os
import queue
import asyncio
import warnings
import peewee as db
from multiprocessing.managers import SyncManager
from multiprocessing import Process, RLock
from data import data