Skip to content

Instantly share code, notes, and snippets.

@zhangw
zhangw / redis_key_sizes.sh
Created December 1, 2020 09:46 — forked from epicserve/redis_key_sizes.sh
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}

Some of the Redis best practices content has moved

This content from this markdown file has moved a new, happier home where it can serve more people. Please check it out : https://docs.microsoft.com/azure/azure-cache-for-redis/cache-best-practices.

NOTE: Client specific guidance listed below is still valid and should still be considered. I will update this document once all content has been moved.

Use Proxy for Git/GitHub

Generally, the Git proxy configuration depends on the Git Server Protocal you use. And there're two common protocals: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on localhost:1080. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later.

SSH Protocol

When you do git clone ssh://[user@]server/project.git or git clone [user@]server:project.git, you're using the SSH protocal. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say ~/.ssh/config:

ProxyCommand nc -x localhost:1080 %h %p
@zhangw
zhangw / MyReflectionTestUtils.java
Created April 20, 2021 12:51 — forked from bmchild/MyReflectionTestUtils.java
Use reflection to compare getters on two objects
/**
*
*/
package com.mypackage.utilities;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.builder.EqualsBuilder;
@zhangw
zhangw / pip_mirror.sh
Created August 12, 2021 13:34 — forked from schnell18/pip_mirror.sh
setup pip mirror in China
mkdir ~/.pip
cat <<EOF > ~/.pip/pip.conf
[global]
trusted-host = mirrors.aliyun.com
index-url = http://mirrors.aliyun.com/pypi/simple
EOF
@zhangw
zhangw / Test.java
Created August 16, 2021 08:55 — forked from nogweii/Test.java
A quick test to see if you have the JCE Unlimited Strength Jurisdiction Policy files installed. If you don't, in Java 6 you'll see 128. If you do, you'll see 2147483647. Thanks to http://stackoverflow.com/questions/11538746/check-for-jce-unlimited-strength-jurisdiction-policy-files
import javax.crypto.Cipher;
class Test {
public static void main(String[] args) {
try {
System.out.println("Hello World!");
int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES");
System.out.println(maxKeyLen);
} catch (Exception e){
System.out.println("Sad world :(");
@zhangw
zhangw / bash_strict_mode.md
Created April 19, 2022 06:12 — forked from mohanpedala/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation
DECLARE
SQLRUN STRING DEFAULT '';
CREATE TEMP FUNCTION
ga4_firebase( key1 STRING,
params ARRAY <STRUCT <key STRING,
value STRUCT <string_value STRING,
int_value INT64,
float_value FLOAT64,
double_value FLOAT64 >>>) AS ( (
SELECT
@zhangw
zhangw / proper_case_function.sql
Created August 26, 2022 09:38 — forked from lacerogers20/proper_case_function.sql
Example of building a simple UDF compared to the standard SQL function
CREATE TEMP FUNCTION
PROPER(str STRING) AS ((
SELECT
STRING_AGG(CONCAT(UPPER(SUBSTR(w,1,1)), LOWER(SUBSTR(w,2))), ' '
ORDER BY
pos)
FROM
UNNEST(SPLIT(str, ' ')) w
WITH
SELECT
date,
COUNT(DISTINCT(visitid)) as unique_visits
FROM `bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE _table_suffix = '20170801' # use date_sub to programmatically select your table
GROUP BY date
ORDER BY date