Skip to content

Instantly share code, notes, and snippets.

@johnsonc
johnsonc / latency.txt
Last active September 11, 2015 11:57 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
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
INSTALLED_APPS = (
'modeltranslation',
'djangocms_admin_style', # for the admin skin. You **must** add 'djangocms_admin_style' in the list **before** 'django.contrib.admin'.
# Boostrap admin theme
# 'django_admin_bootstrapped.bootstrap3',
# 'django_admin_bootstrapped',
# Apps bundled with Django
@johnsonc
johnsonc / nginxproxy.md
Created October 16, 2016 07:54 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@johnsonc
johnsonc / README.md
Created January 20, 2017 19:22 — forked from dominikwilkowski/README.md
Ubuntu 16.04 setup with NGINX http/2 and letsencrypt

Intro

This is a basic collection of things I do when setting up a new headless ubuntu machine as a webserver. Following the steps below should give you a reasonable secure server with HTTP/2 support (including ALPN in chrome) and the fast NGINX server. I am happy to add things so leave a comment.

Basics

After creating the server (droplet on DigitalOcean) log in with

@johnsonc
johnsonc / dcgan.py
Created January 30, 2017 15:57 — forked from soumith/dcgan.py
import torch
import torch.nn as nn
import torch.nn.parallel
class DCGAN_D(nn.Container):
def __init__(self, isize, nz, nc, ndf, ngpu, n_extra_layers=0):
super(DCGAN_D, self).__init__()
self.ngpu = ngpu
assert isize % 16 == 0, "isize has to be a multiple of 16"
@johnsonc
johnsonc / nginx-proxy-geoip
Created February 24, 2017 12:46 — forked from gjuric/nginx-proxy-geoip
nginx - pass GEOIP headers to proxy host
# http block
geoip_city /usr/local/share/GeoIP/GeoIPCity.dat;
geoip_country /usr/local/share/GeoIP/GeoIPCountry.dat;
# location block
proxy_set_header GEOIP_COUNTRY_CODE $geoip_country_code;
proxy_set_header GEOIP_COUNTRY_CODE3 $geoip_country_code3;
proxy_set_header GEOIP_COUNTRY_NAME $geoip_country_name;
@johnsonc
johnsonc / SimpleHTTPServerWithUpload.py
Created April 20, 2018 18:41 — forked from UniIsland/SimpleHTTPServerWithUpload.py
Simple Python Http Server with Upload
#!/usr/bin/env python
"""Simple HTTP Server With Upload.
This module builds on BaseHTTPServer by implementing the standard GET
and HEAD requests in a fairly straightforward manner.
"""
@johnsonc
johnsonc / django_raw_sql_without_model.py
Created January 12, 2019 05:39 — forked from tkrajina/django_raw_sql_without_model.py
Django raw sql without model
from django.db import connection
# If using cursor without "with" -- it must be closed explicitly:
with connection.cursor() as cursor:
cursor.execute('select column1, column2, column3 from table where aaa=%s', [5])
for row in cursor.fetchall():
print row[0], row[1], row[3]