Skip to content

Instantly share code, notes, and snippets.

View toanant's full-sized avatar

Abhishek | अभिषेक toanant

View GitHub Profile
import collections
def generate_flatten(container, contaianer_types=collections.Sequence):
container_list = list(container)
while container_list:
while container_list and isinstance(
container_list[0], contaianer_types):
container_list[0:1] = container_list[0]
if container_list:
@toanant
toanant / latency.markdown
Created October 10, 2016 02:16 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@toanant
toanant / supervisor.conf
Created September 10, 2016 15:10 — forked from tsabat/supervisor.conf
Sample supervisor config file
; Sample supervisor config file.
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)
;chmod=0700 ; sockef file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
;[inet_http_server] ; inet (TCP) server disabled by default
@toanant
toanant / celery.sh
Created September 10, 2016 07:07 — forked from amatellanes/celery.sh
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
sudo dd if=/dev/zero of=/swapfile1 bs=1024 count=8388608
sudo chown root:root /swapfile1
sudo chmod 0600 /swapfile1
sudo mkswap /swapfile1
sudo swapon /swapfile1
free -m
sudo swapon -s
sudo -s
echo '/swapfile1 none swap sw 0 0' >> /etc/fstab
echo 'vm.swappiness=30' >> /etc/sysctl.conf

$cd ~/; openssl dhparam -out dhparams.pem 2048; sudo mv dhparams.pem /etc/ssl/

cd /opt; sudo wget https://dl.eff.org/certbot-auto; sudo chmod a+x certbot-auto

sudo mkdir -p /var/www/<domain name>/ # e.g. /var/www/toanant.in/

from itertools import combinations
def is_palindrome(string):
if string == string[::-1]:
return True
return False
def get_palindrome_length(string):
# Enter your code here. Read input from STDIN. Print output to STDOUT
import copy
all_valid_routes = {
'A': ['AB', ],
'B': ['BC', 'BC', 'BC', 'BD', 'BD', 'BA'],
'C': ['CD', 'CD', 'CD', 'CB', 'CB', 'CB'],
'D': ['DE', 'DC', 'DC', 'DC', 'DB', 'DB'],
'E': ['ED'],
}
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<!DOCTYPE document SYSTEM "rml.dtd">
<document filename="student-feedback.pdf">
<docinit>
<registerTTFont faceName="Arial" fileName="/home/toanant/Xamcheck/codebase/xamcheck-feedback/xamcheck_feedback/static/fonts/Arial.ttf"/>
<registerTTFont faceName="ArialItalic" fileName="/home/toanant/Xamcheck/codebase/xamcheck-feedback/xamcheck_feedback/static/fonts/ArialItalic.ttf"/>
<registerTTFont faceName="ArialBold" fileName="/home/toanant/Xamcheck/codebase/xamcheck-feedback/xamcheck_feedback/static/fonts/ArialBold.ttf"/>
<registerTTFont faceName="ArialBoldItalic" fileName="/home/toanant/Xamcheck/codebase/xamcheck-feedback/xamcheck_feedback/static/fonts/ArialBoldItalic.ttf"/>
</docinit>
<template showBoundary="0" pagesize="(420mm, 297mm)">
@toanant
toanant / snowden-ietf93.md
Last active August 29, 2015 14:27 — forked from mnot/snowden-ietf93.md
Transcript of Edward Snowden's comments at IETF93.