Skip to content

Instantly share code, notes, and snippets.

View aniruddha-adhikary's full-sized avatar

Aniruddha Adhikary (Ani) aniruddha-adhikary

View GitHub Profile
@larrybolt
larrybolt / cf-ddns.sh
Last active April 29, 2024 13:34
Automatically update your CloudFlare DNS record to the IP, Dynamic DNS for Cloudflare
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# Automatically update your CloudFlare DNS record to the IP, Dynamic DNS
# Can retrieve cloudflare Domain id and list zone's, because, lazy
# Place at:
# /usr/local/bin/cf-ddns.sh
@myusuf3
myusuf3 / delete_git_submodule.md
Created November 3, 2014 17:36
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@chengkiang
chengkiang / paynow.js
Last active April 3, 2024 04:24
SG PayNow QR Code Generator Sample
String.prototype.padLeft = function (n, str) {
if (n < String(this).length) {
return this.toString();
}
else {
return Array(n - String(this).length + 1).join(str || '0') + this;
}
}
function crc16(s) {
@danni
danni / fields.py
Created March 8, 2016 08:52
Multi Choice Django Array Field
from django import forms
from django.contrib.postgres.fields import ArrayField
class ChoiceArrayField(ArrayField):
"""
A field that allows us to store an array of choices.
Uses Django 1.9's postgres ArrayField
and a MultipleChoiceField for its formfield.
@hikoz
hikoz / dd.py
Created December 15, 2010 04:45
dd with progress in python
#!/usr/bin/env python
import sys
import time
import signal
from subprocess import Popen, PIPE
dd = Popen(['dd'] + sys.argv[1:], stderr=PIPE)
while dd.poll() is None:
time.sleep(.3)
dd.send_signal(signal.SIGUSR1)
@jaredLunde
jaredLunde / async_lru.py
Last active June 7, 2022 10:09
An LRU cache for asyncio coroutines in Python 3.5
import asyncio
import functools
from collections import OrderedDict
def async_lru(size=100):
cache = OrderedDict()
def decorator(fn):
@functools.wraps(fn)

Performance of Flask, Tornado, GEvent, and their combinations

Wensheng Wang, 10/1/11

Source: http://blog.wensheng.org/2011/10/performance-of-flask-tornado-gevent-and.html

When choosing a web framework, I pretty much have eyes set on Tornado. But I heard good things about Flask and Gevent. So I tested the performance of each and combinations of the three. I chose something just a little more advanced than a "Hello World" program to write - one that use templates. Here are the codes:

1, Pure Flask (pure_flask.py)

@masnun
masnun / alexa.py
Created July 24, 2012 16:02
Python One-liner to get your site's Alexa Rank
#!/usr/bin/env python
import urllib, sys, bs4
print bs4.BeautifulSoup(urllib.urlopen("http://data.alexa.com/data?cli=10&dat=s&url="+ sys.argv[1]).read(), "xml").find("REACH")['RANK']
@theanam
theanam / resize_image_in_frontend.js
Last active September 21, 2021 05:03
A small JavaScipt function to resize image in frontend and return a new JPEG file
/****
Creatd by Anam Ahmed (https://anam.co)
Sample Use:
document.querySelector("input[type=file]").addEventListener("change",function(e){
if(e.target.files.length){
_resample(e.target.files[0],1000,function(response){
console.log(response); // returns an object: {stats:<compression stats>,file:output file}
});
}
});
@hasinhayder
hasinhayder / eid-mubarak.go
Last active February 16, 2018 05:50
Say eid mubarak in different ways :D
package main
// :D :D :D :D
import (
"fmt"
"math/rand"
"time"
)