Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>SuccessfulExit</key>
<false/>
</dict>
<key>Label</key>
class uf {
public:
uf (int n) : arr(n, -1), nc(0) {}
void un (int i, int j) {
int ci = find(i);
if (ci == -1) {
ci = arr[i] = i;
nc++;
}
@ws2356
ws2356 / kubesel
Last active March 29, 2019 03:21
a simple bash script with menu facilitating working with k8s pods
#! /usr/bin/env bash
function kube {
kubectl --kubeconfig=$HOME/Dropbox/wansong.kubeconfig -n c-dev "$@"
}
pat=$1
lines=$(kube get po | grep -E "$pat")
IFSBack=$IFS
@ws2356
ws2356 / gist:bfed1419c72d395d88b948816e1b9fd1
Created March 25, 2019 14:13
osx使用果平方字体
cp -R /Applications/Utilities/Terminal.app/Contents/Resources/Fonts/. /Library/Fonts/
#! /usr/bin/env bash
the_list=''
all_deps=`npm list --depth 0 2>/dev/null | awk '{ print $2 }' | sed -E 's/(.+)@[^@]+/\1/'`
function has_package {
for ddd in $all_deps ; do
if [ "$ddd" = "$1" ] ; then
return 0
fi
@ws2356
ws2356 / avg_agg.sh
Last active March 25, 2019 14:14
从stdin接收数字序列,一行一个,计算累计的均值,输出stdout;输出格式:$cnt, $avg;仅当均值改变才换新行;均值不改变时只更新cnt
#! /usr/bin/env bash
sum=0
cnt=0
last_avg=0
while read -s num ; do
if ! echo "$num" | grep -E '^[0-9]+$' >/dev/null ; then
continue
fi
@ws2356
ws2356 / max_sub_array.cc
Last active March 25, 2019 14:15
[js] calculate max sum of sub array - guarantee selecting at least one number, positive or not, returning both value and range
function maxSubArray(arr) {
let cur_max = arr[0];
let max = cur_max;
let maxi = 0;
let maxj = 0;
let curj = 0;
for (let i = 1; i < arr.length; i++) {
const v = arr[i];
if (cur_max < 0) {
@ws2356
ws2356 / ws_service_client.js
Last active March 15, 2019 23:52
简易websocket脚本客户端
#! /usr/bin/env node
const io = require('socket.io-client')
const {
host = 'http://localhost',
port = 80,
password,
nsp = '/apollon',
room = 'default'
@ws2356
ws2356 / cloudSettings
Last active January 11, 2022 09:07
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-06-20T09:41:02.337Z","extensionVersion":"v3.4.3"}
@ws2356
ws2356 / sed-prepend.sh
Created April 25, 2018 05:24
sed usage: match and prepent multiline
#! /bin/sh
sed -i.bak -E '/doFirst/i\
\ \ \ \ doLast {\
\ \ \ \ def moveFunc = { resSuffix ->\
\ \ \ \ File originalDir = file("${resourcesDir}/drawable-${resSuffix}")\
\ \ \ \ if (originalDir.exists()) {\
File destDir = file("${resourcesDir}/drawable-${resSuffix}-v4")\
ant.move(file: originalDir, tofile: destDir)\
}\