Skip to content

Instantly share code, notes, and snippets.

Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@wwgist
wwgist / psql_hint.txt
Created July 2, 2014 15:51
PSQL: usage hints
# PostgreSQL hints
psql [option...] [dbname [username]]
-U > username (default=unix_user) VEVAR=PGUSER
-W > password
-w > no-password
-d > dbname VEVAR=PGDATABASE
-h > hostname (default=unix_socket/localhost) VEVAR=PGHOST
-p > port (default=default)
@wwgist
wwgist / mysql_hint.txt
Created July 2, 2014 15:27
MYSQL: usage hints
# MySQL hints
mysql [OPTIONS] [database]
mysqladmin [OPTIONS] command command....
-u > user
-p > password
-D > database
-h > host
-P > port
@wwgist
wwgist / singleton.py
Created June 11, 2014 14:44
PYTHON: singletons
# -*- coding: utf-8 -*-
# При вызове метода __new__ каждый раз возвращается один и тот же объект.
# Хранится объект в классовой переменной.
# переопределение __new__ (поверхностно)
class C(object):
instance = None
def __new__(cls):
if cls.instance is None:
@wwgist
wwgist / types.py
Created June 11, 2014 14:09
PYTHON: class creations
"""
Class object creation methods
"""
class Meta(type):
pass
# 1) via definition:
@wwgist
wwgist / timeseqs.py
Created January 1, 2014 13:32
PYTHON: time performance
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import time
reps = 1000
repslist = range(reps)
@wwgist
wwgist / .django_bash_completion.sh
Created October 7, 2013 07:17
DJANGO: bash_completition
# #########################################################################
# This bash script adds tab-completion feature to django-admin.py and
# manage.py.
#
# Testing it out without installing
# =================================
#
# To test out the completion without "installing" this, just run this file
# directly, like so:
#
@wwgist
wwgist / .bashrc
Created October 6, 2013 07:25
UBUNTU: .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# don't put duplicate lines in the history
export HISTCONTROL=ignoreboth:erasedups
# set history length
@wwgist
wwgist / file_upload.html
Created July 12, 2013 09:43
HTML5: files upload
<!-- via control upload -->
<input type="file" id="your-files" multiple>
<script>
var control = document.getElementById("your-files");
control.addEventListener("change", function(event) {
// When the control has changed, there are new files
var i = 0,
files = control.files,
@wwgist
wwgist / .gitattributes
Created June 20, 2013 05:49
GIT: .gitattributes
# file rule
#----------------
* text=auto
*.rb text
*.js text
*.bat text eol=crlf
*.sh text eol=lf
*.png binary