Skip to content

Instantly share code, notes, and snippets.

Avatar

Chopin Ngo consatan

  • Amoy, Fujian, China
View GitHub Profile
@consatan
consatan / get_dockerfile_from_image.sh
Created May 7, 2022
get Dockerfile from docker image
View get_dockerfile_from_image.sh
docker image history --no-trunc --format '{{.CreatedBy}}' IMAGE_NAME:TAG | tac
@consatan
consatan / gzip_log_file_by_mtime.sh
Created Feb 23, 2022
find by mtime older than today midnight
View gzip_log_file_by_mtime.sh
#! /bin/bash
# v.a. https://unix.stackexchange.com/a/257966
# -daystart -mtime +0 表示文件的 mtime 时间在当天 0 点前(用于保留最新的一个文件)
# 如果没有 -daystart 的话,表示 文件的 mtime 时间在 24 小时前(用于保留最新的2个文件)
find ./ -maxdepth 1 -type f -name '*.log' -daystart -mtime +0 -exec gzip {} \;
@consatan
consatan / windows_optimize_vhd_file.txt
Created Nov 26, 2021
Windows release WSL2 and docker VHD file quota
View windows_optimize_vhd_file.txt
WSL2 vhd location
C:\Users\{USERNAME}\AppData\Local\Packages\{DISTRO}\LocalState\{DISTRO_PACKAGE_NAME}\ext4.vhdx
Docker for Windows vhd location
C:\Users\{USERNAME}\AppData\Local\Docker\wsl\data\ext4.vhdx
# delete unuse volume
docker volume prune
exit docker for windows (Right-clicking the whale icon in the notification area (bottom right) > Quit Docker Desktop)
View redis_pop_multip_benchmark.php
<?php
// redis lua script use LRANGE and LTRIM
// redis-cli SCRIPT LOAD "local res; res = redis.call('LRANGE', KEYS[1], 0, ARGV[1] - 1); redis.call('LTRIM', KEYS[1], ARGV[1], -1); return res"
// script sha1: 163b2d3e271c4b0ca837426d9c0fffd9fc5bf591
// redis lua script use LPOP loop
// SCRIPT LOAD "local res = {}; for i=ARGV[1],1,-1 do table.insert(res, redis.call('LPOP', KEYS[1])); end; return res"
// script sha1: 015204a29f59eca28a9079f0246ec9a25871b031
// Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz 3.19 1x16G 2666MHz
@consatan
consatan / strtr.js
Created Sep 9, 2021
php strtr 函数的 js 实现,用于实现简单的自定义编码,如 自定义 base64 编码
View strtr.js
// php strtr 函数的 js 实现 v.a. https://www.php.net/manual/en/function.strtr.php
// 只实现了 strtr(string $str, array $replace_pairs) 这种调用方法,且 replace_pairs 里只能是单个字符替换为单个字符
// 目的是为了做凯撒密码实现
String.prototype.strtr = function(dic) {
return this.toString().split('').map(char => dic[char] || char).join('');
}
// 调用
let str = '123321123';
@consatan
consatan / curl_imap_query_commands.md
Last active Aug 25, 2020 — forked from akpoff/curl_imap_query_commands.md
curl commands to query imap servers
View curl_imap_query_commands.md

curl commands to query imap servers

Based on https://busylog.net/telnet-imap-commands-note/

curl options

  • -k -- don't verify certificate (optional)
  • -n -- use .netrc for username and password (optional)
  • -X -- request to send to server
@consatan
consatan / only_jd.js
Created Apr 17, 2020
只看京东自营产品
View only_jd.js
// ==UserScript==
// @name 京东只看自营
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 只看京东自营产品
// @author Chopin Ngo <consatan@gmail.com>
// @match https://list.jd.com/list.html*
// @grant none
// ==/UserScript==
@consatan
consatan / random_password.sh
Last active Mar 19, 2020
Generate random password
View random_password.sh
# Usage: rpasswd [LENGTH] [CHARS]
# Generate random password
#
# CHARS
# 'a': Alphabet, a-z A-Z
# 'n': Numeric, 0-9
# 'c': Character, print characters in ascii code
#
rpasswd() {
len=12
View select2_extended_ajax_adapter.js
$.fn.select2.amd.define('select2/data/extended-ajax',['./ajax', './tags', '../utils', 'module', 'jquery'], function(AjaxAdapter, Tags, Utils, module, $) {
function ExtendedAjaxAdapter ($element,options) {
//we need explicitly process minimumInputLength value
//to decide should we use AjaxAdapter or return defaultResults,
//so it is impossible to use MinimumLength decorator here
this.minimumInputLength = options.get('minimumInputLength');
this.defaultResults = options.get('defaultResults');
ExtendedAjaxAdapter.__super__.constructor.call(this,$element,options);
}
View .cvimrc
let searchalias g = "google"
let barposition = "bottom"
let scrollstep = 70
let searchengine php = ["http://php.net", "http://php.net/manual-lookup.php?scope=quickref&pattern=%s"]
let searchengine fy = "https://translate.google.com/#zh-CN/en/"
let completionengines = ["google", "php", "fy"]
unmap E R K J d x b B u e D f F
map h previousTab
map l nextTab
map d closeTab