Skip to content

Instantly share code, notes, and snippets.

View danishabdullah's full-sized avatar

Danish Abdullah danishabdullah

  • Berlin, Germany
View GitHub Profile
@danishabdullah
danishabdullah / In the Beginning was the Command Line - by Neal Stephenson.md
Last active August 29, 2015 14:04
In the Beginning was the Command Line - by Neal Stephenson

About twenty years ago Jobs and Wozniak, the founders of Apple, came up with the very strange idea of selling information processing machines for use in the home. The business took off, and its founders made a lot of money and received the credit they deserved for being daring visionaries. But around the same time, Bill Gates and Paul Allen came up with an idea even stranger and more fantastical: selling computer operating systems. This was much weirder than the idea of Jobs and Wozniak. A computer at least had some sort of physical reality to it. It came in a box, you could open it up and plug it in and watch lights blink. An operating system had no tangible incarnation at all. It arrived on a disk, of course, but the disk was, in effect, nothing more than the box that the OS came in. The product itself was a very long string of ones and zeroes that, when properly installed and coddled, gave you the ability to manipulate other very long strings of ones and zeroes. Even those few who actually understood what

@danishabdullah
danishabdullah / Locked and locking queries in postgresql.md
Last active August 29, 2015 14:08
Locked and locking queries in postgresql
CREATE VIEW blocking_processes AS
SELECT 
    pg_locks2.pid as blocking_pid,
    ka.usename as blocking_user,
    ka.query as blocking_query,
    pg_locks1.pid as blocked_pid,
    psa.usename as blocked_user, 
    psa.query as blocked_query, 
    to_char(age(now(), psa.query_start),'HH24h:MIm:SSs') as age
@danishabdullah
danishabdullah / Get table and index sizes in Postgresql.md
Last active August 29, 2015 14:09
Get table and index sizes in Postgresql
SELECT
    table_name,
    pg_size_pretty(table_size) AS table_size,
    pg_size_pretty(indexes_size) AS indexes_size,
    pg_size_pretty(total_size) AS total_size
FROM (
    SELECT
        table_name,
 pg_table_size(table_name) AS table_size,
@danishabdullah
danishabdullah / delete unnecessary branches.md
Created December 5, 2014 13:55
delete unnecessary branches in git
for k in $(git branch | sed /\*/d); do 
  if [ -n "$(git log -1 --since='12 week ago' -s $k)" ]; then
    git branch -D $k
  fi
done
@danishabdullah
danishabdullah / MultiProcessingLog.py
Created June 4, 2015 11:35
Python logger for multiprocessing
import multiprocessing, threading, logging, sys, traceback
class MultiProcessingLog(logging.Handler):
def __init__(self, name, mode='w', maxsize=0, rotate=0):
logging.Handler.__init__(self)
self._handler = logging.handlers.RotatingFileHandler(name, mode, maxsize, rotate, encoding='utf-8')
self.queue = multiprocessing.Queue(-1)
t = threading.Thread(target=self.receive)
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@danishabdullah
danishabdullah / S3Storage.md
Last active February 10, 2016 13:24
Boto3 S3 helper

Following example class shows how to use boto3 to upload files to s3 using a programmable configuration

from uuid import uuid1

import boto3
from botocore.client import Config
from boto3.session import Session

class S3Storage(object):
@danishabdullah
danishabdullah / Cast for postgres IN statement.md
Created February 11, 2016 15:28
Cast for postgres IN statement
def cast_for_in_statement(iterable):
    iterable = ["'{}'".format(n) for n in iterable]
    return "({})".format(", ".join(iterable))
@danishabdullah
danishabdullah / Get dicts for sqlalchemy core query.md
Last active February 11, 2016 15:49
Get dicts for sqlalchemy core query
def make_dicts_from_result_proxy(proxy):
    res = proxy.fetchall()
    if res:
        keys = res[0].keys()
        res = [dict(zip(keys, i.values())) for i in res]
    return res

make_dicts_from_result_proxy(engine.execute("SELECT * FROM example"))