Skip to content

Instantly share code, notes, and snippets.

@cuixin
cuixin / lua_safe_random.lua
Created Jan 3, 2020
generate lua safe random numbers
View lua_safe_random.lua
for i = 1, 10000 do
local t = os.time()
local c = os.clock()
local seed = t + (c*1000000)
math.randomseed(seed)
print(t, c, seed, math.random(1, 2147483647))
end
@cuixin
cuixin / redis-migrate.sh
Created Dec 19, 2019 — forked from nicStuff/redis-migrate.sh
Comfort tool for migrating redis keys among instances. Supports KEYS syntax matching, authentication and TTL
View redis-migrate.sh
#!/bin/bash
######
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
######
@cuixin
cuixin / lua_match_pattern.lua
Created Aug 26, 2019
lua match pattern example.
View lua_match_pattern.lua
local Receiver = {} do
Receiver.__index = Receiver
function Receiver.new(t)
return setmetatable(t or {}, Receiver)
end
function Receiver:__newindex(k, v)
assert(type(v) == "function")
local curr = self
for comp in k:gmatch "(%w+)" do
@cuixin
cuixin / tinypng.sh
Created Jan 4, 2019
tinpng bash example
View tinypng.sh
#!/bin/bash
function tinypng() {
if [[ -z $APK_KEY ]]; then
echo "API_KEY not defined";
return 1;
fi
if [[ -z $1 ]]; then
echo "path is empty";
return 1;
fi
@cuixin
cuixin / nginx_proxy_by_query.conf
Last active Dec 28, 2018
nginx proxy_pass by query param(query url) example
View nginx_proxy_by_query.conf
events {
}
http {
server {
listen 80;
server_name localhost;
location / {
set $host_1 "http://127.0.0.1:8881";
set $host_2 "http://127.0.0.1:8882";
@cuixin
cuixin / wallpaper.sh
Created Dec 20, 2018
random desktop wallpaper from unsplash website.
View wallpaper.sh
#!/bin/bash
function wallpaper() {
# set -ex
query=$1
if [[ -z $query ]]; then
query="wallpaper"
fi
pic_path="/tmp/wallpaper.jpg"
wget "https://source.unsplash.com/random/1920x1080?$query" -O $pic_path
feh --no-fehbg --image-bg "#000000" --bg-max $pic_path
@cuixin
cuixin / bitset.go
Created Nov 8, 2018
dummy bitset in golang
View bitset.go
package main
import (
"encoding/binary"
"encoding/json"
"errors"
"fmt"
"strings"
"log"
@cuixin
cuixin / tsr.bash
Created Oct 22, 2018
typescript run command(add this function in ur .bashrc or .zshrc)
View tsr.bash
function tsr() {
tsc $1.ts && node $1.js
}
@cuixin
cuixin / table_dump.lua
Last active Jul 17, 2019
lua table.dump to dump a whole table to print_r.
View table_dump.lua
local type = type
local tostring = tostring
local table = table
local table_insert = table.insert
local table_concat = table.concat
local pairs = pairs
return function(t, name, indent)
local table_list = {}
local function table_r(t, name, indent, full)
@cuixin
cuixin / fibonacci.lua
Created Jul 6, 2018
lua fibonacci with closure.
View fibonacci.lua
local function my_ipairs(t)
local i = 1
return function()
local v = t[i]
if v then
local ii = i
i = i + 1
return ii, v
else
return nil
You can’t perform that action at this time.