NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
""" | |
Add copy to clipboard from IPython! | |
To install, just copy it to your profile/startup directory, typically: | |
~/.ipython/profile_default/startup/ | |
updated version: https://gist.github.com/bwagner/270da7c7d31af7ffaca32674557fc172 | |
Example usage: |
CC=gcc | |
CFLAGS=-Wall -Wextra -Wpedantic | |
LDFLAGS= | |
SOURCES=$(wildcard *.c ) | |
OBJECTS=$(SOURCES:.c=.o) | |
EXECUTABLE=exec | |
all: $(EXECUTABLE) | |
./$(EXECUTABLE) |
# Assumes the database container is named 'db' | |
DOCKER_DB_NAME="$(docker-compose ps -q db)" | |
DB_HOSTNAME=db | |
DB_USER=postgres | |
LOCAL_DUMP_PATH="path/to/local.dump" | |
docker-compose up -d db | |
docker exec -i "${DOCKER_DB_NAME}" pg_restore -C --clean --no-acl --no-owner -U "${DB_USER}" -d "${DB_HOSTNAME}" < "${LOCAL_DUMP_PATH}" | |
docker-compose stop db |
<?php | |
use Aws\Kms\KmsClient; | |
// Somewhere in the controller or model | |
$this->load->config('aws'); | |
// Not needed for EC2 instance role based authorization - for my local instance only | |
$key = $this->config->item('aws_s3_access_key'); | |
$secret = $this->config->item('aws_s3_secret_key'); |
<ul class="nav navbar-nav"> | |
<li{% if app_name == 'pages' %} class="active"{% endif %}> | |
<a href="{% url "page_list" %}">{% trans "Pages" %}</a> | |
</li> | |
</ul> |
NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
import shutil, tempfile | |
from os import path | |
import unittest | |
class TestExample(unittest.TestCase): | |
def setUp(self): | |
# Create a temporary directory | |
self.test_dir = tempfile.mkdtemp() | |
def tearDown(self): |
def bytesto(bytes, to, bsize=1024): | |
"""convert bytes to megabytes, etc. | |
sample code: | |
print('mb= ' + str(bytesto(314575262000000, 'm'))) | |
sample output: | |
mb= 300002347.946 | |
""" | |
a = {'k' : 1, 'm': 2, 'g' : 3, 't' : 4, 'p' : 5, 'e' : 6 } |
def consumer(func): | |
""" | |
See: http://www.dabeaz.com/generators/ | |
""" | |
def start(*args,**kwargs): | |
c = func(*args,**kwargs) | |
c.next() | |
return c | |
return start |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
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 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |