Skip to content

Instantly share code, notes, and snippets.

View nanmu42's full-sized avatar

Zhennan LI nanmu42

View GitHub Profile
@dopey
dopey / main.go
Last active April 22, 2025 12:17 — forked from denisbrodbeck/main.go
How to generate secure random strings in golang with crypto/rand.
package main
import (
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"math/big"
)
@nauar
nauar / pre-receive
Last active March 13, 2024 08:45
GIT pre-receive hook for checking file size and filename extensions
#!/bin/bash
# This script is a pre-receive hook allowing pushes whose every file:
# - is smaller than 20 M
# - and its extension is not one of the following:
# - dll
# - exe
# - war
# - ear
# - jar
{
"123":"application/vnd.lotus-1-2-3",
"ez":"application/andrew-inset",
"aw":"application/applixware",
"atom":"application/atom+xml",
"atomcat":"application/atomcat+xml",
"atomsvc":"application/atomsvc+xml",
"ccxml":"application/ccxml+xml",
"cdmia":"application/cdmi-capability",
"cdmic":"application/cdmi-container",
@denisbrodbeck
denisbrodbeck / main.go
Last active February 2, 2023 22:35
How to generate secure random strings in golang with crypto/rand.
// License: MIT
package main
import (
"crypto/rand"
"fmt"
"math/big"
)
// GenerateRandomASCIIString returns a securely generated random ASCII string.
@afc163
afc163 / cascader-address-options.js
Last active August 24, 2024 15:24
Address options for antd cascader
import provinces from 'china-division/dist/provinces.json';
import cities from 'china-division/dist/cities.json';
import areas from 'china-division/dist/areas.json';
areas.forEach((area) => {
const matchCity = cities.filter(city => city.code === area.cityCode)[0];
if (matchCity) {
matchCity.children = matchCity.children || [];
matchCity.children.push({
label: area.name,
@JPvRiel
JPvRiel / gnome_proxy_to_env.md
Last active May 24, 2023 12:15
a shell wrapper to pull org.gnome.proxy settings into env, e.g. http_proxy, which is useful for .desktop files

Why?

Useful for:

  • updating current terminal's shell env proxy settings, or
  • wrapping exec in .desktop files to inject env proxy settings

GNOME proxy settings should normally get propergated into the shell (bash) environment via gnome-terminal, e.g. http_proxy and no_proxy. However:

  • I noticed that applications exectuted via .desktop entries sometimes don't work. This happens when an app ignores org.gnome.proxy settings but can often use proxy env vars from the shell.
  • If you're proxy settings change, existing shell processes will still have the old proxy enviroment variables, so this can help refresh them whithout having to create a new shell.
@JonCole
JonCole / Redis-BestPractices-General.md
Last active March 13, 2025 14:30
Redis Best Practices

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.

@jaymecd
jaymecd / golang-auto-build-versioning.md
Last active January 6, 2025 22:43
Golang Auto Build Versioning
go run -ldflags "-s \
  -X main.Version=1.0.2 \
  -X main.BuildTime=`TZ=UTC date -u '+%Y-%m-%dT%H:%M:%SZ'` \
  -X main.GitHash=`git rev-parse HEAD`" \
  myapp.go

Adopted from www.atatus.com

@jonfk
jonfk / virtualenv.adoc
Last active February 28, 2023 02:22
Python Virtualenv Cheatsheet

Virtualenv Cheatsheet

  1. Create a virtualenv

    $ virtualenv env
  2. Activate

@glen-cheney
glen-cheney / encoding-video.md
Last active November 24, 2024 10:09
Encoding video for the web

Encoding Video

Installing

Install FFmpeg with homebrew. You'll need to install it with a couple flags for webm and the AAC audio codec.

brew install ffmpeg --with-libvpx --with-libvorbis --with-fdk-aac --with-opus