Skip to content

Instantly share code, notes, and snippets.

@zhangw
zhangw / redis-delallbykey
Created December 19, 2017 11:14 — forked from mattweyant/redis-delallbykey
Delete all keys from Redis matching a regular expression
# All credit: http://stackoverflow.com/questions/4006324/how-to-atomically-delete-keys-matching-a-pattern-with-redis
redis-cli [options] KEYS "prefix:*" | xargs redis-cli [options] DEL
@zhangw
zhangw / 开放平台鉴权学习.md
Created November 28, 2017 16:07 — forked from arganzheng/开放平台鉴权学习.md
开放平台点滴积累

鉴权学习

对于一个API请求,开发平台一般需要知道下面几件事情:

  1. 哪个应用发起这个请求(Which application is making the request)
  2. 这个请求是为哪个用户发起的(Which user the request is posting on behalf of)
  3. 用户是否对这个请求进行授权(Whether the user has granted the application authorization to post on the user's behalf)
  4. 请求是否在传输过程中被篡改(Whether the request has been tampered by a third party while in transit)
@zhangw
zhangw / flatten_implementation.py
Created November 10, 2017 12:26
ways of python flatten
# -*- coding: utf-8 -*-
"""
flatten_implementation.py
----------
ways of python flatten
-----------------------------------------------------
Created by <[email protected]> on Nov 10,2017
"""
class LambdaFlatten():
@staticmethod
@zhangw
zhangw / cpus_number.py
Created October 30, 2017 07:32
how-to-find-out-the-number-of-cpus-using-python
import os
import re
import subprocess
#https://stackoverflow.com/questions/1006289/how-to-find-out-the-number-of-cpus-using-python/14840102
def available_cpu_count():
""" Number of available virtual or physical CPUs on this system, i.e.
user/real as output by time(1) when called with an optimally scaling
userspace-only program"""
@zhangw
zhangw / encryption.java
Created October 24, 2017 04:46 — forked from itarato/encryption.java
Java AES CBC encryption example
package com.company;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest;
import java.security.SecureRandom;
public class Main {
@zhangw
zhangw / python
Created September 12, 2017 05:47
CamelCase to camel_case
import re
def Camel2Snake(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
@zhangw
zhangw / README.md
Created January 26, 2017 08:09 — forked from jimothyGator/README.md
Nginx configuration for Mac OS X with Homebrew, using sites-enabled directory.
mkdir -p /usr/local/etc/nginx/sites-{enabled,available}
cd /usr/local/etc/nginx/sites-enabled
ln -s ../sites-available/default.conf
ln -s ../sites-available/default-ssl.conf

File locations:

  • nginx.conf to /usr/local/etc/nginx/
  • default.conf and default-ssl.conf to /usr/local/etc/nginx/sites-available
  • homebrew.mxcl.nginx.plist to /Library/LaunchDaemons/
@zhangw
zhangw / latency.txt
Created October 26, 2016 02:55 — 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 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
@zhangw
zhangw / Git checkout remote branch
Created October 13, 2016 07:43 — forked from markSci5/Git checkout remote branch
Git checkout remote branch
//To fetch a branch, you simply need to:
git fetch origin
//This will fetch all of the remote branches for you. With the remote branches
//in hand, you now need to check out the branch you are interested in, giving
//you a local working copy:
git checkout -b test origin/test
@zhangw
zhangw / Sublime Text 3 Build 3103 License Key - CRACK
Created May 31, 2016 08:57
Sublime Text 3 Build 3103 License Key - CRACK
I use the first
—– BEGIN LICENSE —–
Michael Barnes
Single User License
EA7E-821385
8A353C41 872A0D5C DF9B2950 AFF6F667
C458EA6D 8EA3C286 98D1D650 131A97AB
AA919AEC EF20E143 B361B1E7 4C8B7F04