Skip to content

Instantly share code, notes, and snippets.

@Martin91
Martin91 / .git_scripts_check_branchs.sh
Created December 22, 2020 03:02
git scan released branches
#!/bin/zsh
specialBranches=("master" "uat" "test" "release")
echo "\u001b[31mScanning released local branches...\n--------------------------------------------------------\u001b[0m"
releasedLocalBranches=()
for branch in $(git branch)
do
git show-ref -s --heads $branch | xargs git branch --contains | grep master > /dev/null
if [[ $? -eq 0 && ! " ${specialBranches[@]} " =~ " ${branch} " ]]; then
@Martin91
Martin91 / sshtunnel.go
Last active April 18, 2023 06:49
Connect to a database via SSH tunnel
// Package internal ...
package internal
import (
"fmt"
"github.com/go-sql-driver/mysql"
"golang.org/x/crypto/ssh"
"net"
)
@Martin91
Martin91 / mvcc.py
Last active February 24, 2023 21:07 — forked from elliotchance/transaction_example.py
https://elliot.land/implementing-your-own-transactions-with-mvcc, fixed a few runtime errors in the original gist and simulate a case that updating a deleting record
next_xid = 1
active_xids = set()
records = []
class TransactionConflictError(RuntimeError):
pass
def new_transaction():
@Martin91
Martin91 / jsonbench.go
Created November 25, 2022 07:59
Benchmark mysql with simple read, update and insert json by JSON type and text type
package jsonbench
import (
"database/sql"
"fmt"
"math/rand"
)
var (
jsonPattern = "{\"value\": \"%s\"}"
@Martin91
Martin91 / hotp.rb
Last active January 29, 2022 14:16
OTP algorithms in Ruby
require 'openssl'
def hotp(secret, counter, digits = 6)
hash = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), secret, int_to_bytestring(counter))
"%0#{digits}i" % (truncate(hash) % 10**digits)
end
def truncate(string)
offset = string.bytes.last & 0xf
partial = string.bytes[offset..offset+3]
@Martin91
Martin91 / containsAny.go
Last active May 20, 2021 01:54
containsAny in Golang
package main
import (
"fmt"
"reflect"
)
func containsAny(data interface{}, element ...interface{}) bool {
rVal := reflect.ValueOf(data)
switch rVal.Kind() {
@Martin91
Martin91 / postman-pre-request-script-for-shopee-openapi.js
Last active April 16, 2021 17:06
Postman Pre-request script for Shopee OpenAPI's authentication
var CryptoJS = require("crypto-js");
var Property = require('postman-collection').Property;
var now = new Date();
var timestampNow = parseInt(now.getTime() / 1000);
pm.collectionVariables.set("timestamp", timestampNow);
var host = pm.collectionVariables.get("host");
var path = pm.request.url.getPath();
var requestURL = host + path;
@Martin91
Martin91 / track_original_repo.sh
Created July 2, 2013 12:37
Make Your Fork Track the Original Upstream Repo
git remote add --track master upstream git://github.com/upstreamname/projectname.git
git fetch upstream
git merge upstream/master
@Martin91
Martin91 / explain_sqls.sql
Last active March 2, 2020 14:53
MySQL ORDER BY primary key which is not in WHERE CLAUSE performs slowly
/* use condition > */
mysql> EXPLAIN SELECT * FROM test WHERE `test`.`activeday` > 10000 AND `test`.`deleted` = 0 ORDER BY id ASC LIMIT 20\G;
*************************** 1. row ***************************
possible_keys: index_on_test_to_activeday
key: PRIMARY
key_len: 4
rows: 40
filtered: 5.00
Extra: Using where
@Martin91
Martin91 / output.txt
Created June 12, 2019 07:07
supervisord XML/RPC API demo
==================== Supported Methods ======================
['supervisor.addProcessGroup', 'supervisor.clearAllProcessLogs', 'supervisor.clearLog', 'supervisor.clearProcessLog', 'supervisor.clearProcessLogs', 'supervisor.getAPIVersion', 'supervisor.getAllConfigInfo', 'supervisor.getAllProcessInfo', 'supervisor.getIdentification', 'supervisor.getPID', 'supervisor.getProcessInfo', 'supervisor.getState', 'supervisor.getSupervisorVersion', 'supervisor.getVersion', 'supervisor.readLog', 'supervisor.readMainLog', 'supervisor.readProcessLog', 'supervisor.readProcessStderrLog', 'supervisor.readProcessStdoutLog', 'supervisor.reloadConfig', 'supervisor.removeProcessGroup', 'supervisor.restart', 'supervisor.sendProcessStdin', 'supervisor.sendRemoteCommEvent', 'supervisor.shutdown', 'supervisor.signalAllProcesses', 'supervisor.signalProcess', 'supervisor.signalProcessGroup', 'supervisor.startAllProcesses', 'supervisor.startProcess', 'supervisor.startProcessGroup', 'supervisor.stopAllProcesses', 'supervisor.stopProcess'