Skip to content

Instantly share code, notes, and snippets.

View iwinux's full-sized avatar
👽

Limbo Peng iwinux

👽
View GitHub Profile
@jboner
jboner / latency.txt
Last active May 3, 2024 15:17
Latency Numbers Every Programmer Should Know
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
@spion
spion / a-warning.md
Last active March 25, 2024 03:01
C++ versus V8 versus luajit versus C benchmark - (hash) tables

Warning

This benchmark has been misleading for a while. It was originally made to demonstrate how JIT compilers can do all sorts of crazy stuff to your code - especially LuaJIT - and was meant to be a starting point of discussion about what exactly LuaJIT does and how.

As a result, its not indicative of what its performance may be on more realistic data. Differences can be expected because

  1. the text will not consist of hard-coded constants
#
# Instructions for making hybrid GPT/MBR boot USB thumb drive.
# The Slackware Linux installer will be added to the image as an example,
# however the syslinux configuration can be modified to include any desired
# image.
#
# A USB thumb drive formatted with these instructions was able to
# boot the Slackware Installer on a:
#
# Dell Latitude E6430 in Legacy BIOS mode
"Memcached cache backend"
from django.core.cache.backends import memcached
from django.utils.encoding import smart_unicode, smart_str
MIN_COMPRESS_LEN = 150000
class CacheClass(memcached.CacheClass):
def add(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
if isinstance(value, unicode):
@stuartsierra
stuartsierra / lein2-issue.md
Created July 6, 2012 21:04
'file:' repositories in Leiningen 2.0.0-preview5 and later

Sample Project

Starting from:

lein new foo
cd foo

Say I have a random JAR file that is not available in any repository:

touch README.md

@a-chernykh
a-chernykh / avatar_uploader.rb
Created August 9, 2011 14:28
CarrierWave extension-aware remote file downloading
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
def extension_white_list
model.skip_avatar_extension_check ? nil : %w(jpg jpeg gif png bmp)
end
end
@jpetazzo
jpetazzo / gist:6127116
Created July 31, 2013 23:21
Debian/Ubuntu containers protips, thanks to @spahl
# this forces dpkg not to call sync() after package extraction and speeds up install
RUN echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup
# we don't need and apt cache in a container
RUN echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache
@Blankwonder
Blankwonder / gist:cd9fa1987e41cf1a1f1df50583ba1d9c
Created November 14, 2017 04:48
client-side SSL/TLS certificate validation
[Proxy]
TestTLS = https, 192.168.20.6, 443, client-cert=item
[Keystore]
item = password=123456, base64=MIILqQIBAzCCC28GCSqGSIb3DQEHAaCCC2AEggtcMIILWDCCBg8GCSqGSIb3DQEHBqCCBgAwggX8AgEAMIIF9QYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIh4LPGCPkcqkCAggAgIIFyDOP/a/YB66H0jctVC5/D3ZF98es9Xtf60hqDokaekMp7VlKhr7EEvf1GrmxOY9XqO1dSR0F2C17yefazR7lZVDwfmNvU8eEpIPrBAnqSnCFyMZGXjcu9aoEySkwRlSclqg9lbFhp9XZG4F4qRuo94mlTPDy47dvdzyiPAQPBIq2DOE/qbRVHqrbnZMkUZi1lxihRRcQv7YJAfLEP2VHffjZTYzlBMi/ldKyD4ZQdpM7mdBtHXFa21ZV9j4oqM2PWWToHwIxkeiS6J2SgfEg501QEy4kbihlp+pSK4OMrj33DrVFP9rOMDnkJtQ+EP0LXXQBaF+7rRp+dekcH+sYBQF0cDMhNEkHEBL8LoQ96hZxIDxE3YQ6fq9KGi4TV8Ktkgb2l0G5DoavN8dhCKS5Gx0nexDT8vj91Js94Xt4tFThSyoc4ZmZvN+b2ugqVvYsnWaKqS8UeAjIAFsZCiLgj4OG6frrAxI+V3c8kL9FrwfFQcL9eWoqVfhBv8SKzMYObTv9FwyJn/fyGdtoT19OpyWiP1+nU+WY7e5KjcJNsKeYolgpgHDXdOSYCakQfesENeeKqvzMA6Quj7g7gZl/AB/GjRybyAXfkxyYBLk5cz7MuDcM1nk6DR47IuHBHyrwOATXyejWYrlK0QUVUsFEmM2vjl38jU8+qxjVWDTFu3gQkFBERncJp1XnKSTueDEPkdeq1BzV1SZ1m1KHNPNI4h2lPa+IKvpYbnDure9n1VV7fk2ySJrBFT5pYonXdpyaCTAvTEFk
@Linusp
Linusp / finance.py
Last active January 10, 2021 07:32
计算达到资产目标需要多少年
import click
@click.command()
@click.option("--age", type=int, default=24, help="你当前的年龄")
@click.option("--asset", type=float, default=0, help="上一年年末总资产")
@click.option("--salary", type=float, default=200000, help="预计今年年工作收入")
@click.option("--salary-rate", type=float, default=0.1, help="预计工作收入年增长率")
@click.option("--invest", type=float, default=10000, help="预计今年投资收入")
@click.option("--invest-rate", type=float, default=0.1, help="预计投资收入年增长率")
@click.option("--expense", type=float, default=90000, help="预计今年支出")
@dannypurcell
dannypurcell / trailing-slash-middleware
Created January 2, 2014 05:30
Ring middleware fn. Removes a trailing slash from the uri before calling the handler.
(defn ignore-trailing-slash
"Modifies the request uri before calling the handler.
Removes a single trailing slash from the end of the uri if present.
Useful for handling optional trailing slashes until Compojure's route matching syntax supports regex.
Adapted from http://stackoverflow.com/questions/8380468/compojure-regex-for-matching-a-trailing-slash"
[handler]
(fn [request]
(let [uri (:uri request)]
(handler (assoc request :uri (if (and (not (= "/" uri))