Skip to content

Instantly share code, notes, and snippets.

View SSARCandy's full-sized avatar
🔭
💤

Andy Hsu SSARCandy

🔭
💤
View GitHub Profile
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
@SSARCandy
SSARCandy / .gitconfig
Created June 8, 2020 02:46
useful gitconfig
[alias]
l = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%ae>%Creset' --abbrev-commit
@SSARCandy
SSARCandy / fetch_servers.sh
Last active November 11, 2018 13:30
Using pdsh to fetch multiple servers status and output JSON format data
#!/bin/bash
status_file='./status'
status_json_file='./status.json'
hosts="cml[4,22]"
cmd_hostname="cat /etc/hostname | tr '\n' ','"
cmd_uptime_and_avgload="uptime | sed 's/[0-9]*:[0-9]*,//' | sed 's/.*up//' | sed 's/load average://' | tr '\n' ','"
cmd_cpuinfo="cat /proc/cpuinfo | grep processor | wc -l | tr '\n' ','"
cmd_meminfo="cat /proc/meminfo | egrep '^MemTotal|^MemAvailable|^SwapTotal|^SwapFree|^Cached' | tr 'kB' ' ' | awk -F ':' '{printf(\$2\",\")}'"
cmd_lastupdate="date +'%H:%M:%S'"
@SSARCandy
SSARCandy / plot.py
Created March 16, 2018 10:26
Manipulate visdom data
import matplotlib.pyplot as plt
import numpy as np
import json
def getWindowsName(data):
d = data['jsons']
a = d.keys()
for k in a:
print(k, d[k]['title'])
@SSARCandy
SSARCandy / list_account_expire_status.sh
Last active January 4, 2018 10:37
list account expire status
#/bin/bash
sudo cat /etc/shadow \
| awk -F : -v d=$(expr `date +%s` / 86400) \
'{
if ($8 >= 0) {
if ($8 > d || $8 <= 0) printf "%15s %5d %s\n", $1, $8, "";
else printf "%15s %5d %s\n", $1, $8, "Expired";
}
}' \
@SSARCandy
SSARCandy / cex_private_api_auth.gs
Last active December 30, 2017 04:14
CEX.IO private API auth in Google apps scripts (google sheet)
function cex_auth(command, user_id, key, secret, callback) {
var uri = "https://cex.io/api/";
var nonce = new Date().getTime();
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, nonce.toString()+user_id+key, secret);
var stringSignature = signature.map(function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('').toUpperCase();
var params = {
@SSARCandy
SSARCandy / cex_private_api_auth.gs
Created December 30, 2017 04:12
Google apps scripts for CEX.io private api auth
function cex_auth(command, user_id, key, secret, callback) {
var uri = "https://cex.io/api/";
var nonce = new Date().getTime();
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_256, nonce.toString()+user_id+key, secret);
var stringSignature = signature.map(function(byte) {
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
}).join('').toUpperCase();
var params = {
@SSARCandy
SSARCandy / index.js
Last active November 15, 2017 08:53
auto upload to phancer and get the result
const fs = require('fs');
const request = require('request-promise');
const option = {
method: 'POST',
uri: 'http://phancer.com/upload?net=iphone_6',
formData: {
file: {
value: fs.createReadStream('image_.jpg'),
options: {
@SSARCandy
SSARCandy / gpu-occupy-status.sh
Last active August 26, 2021 17:18
Show GPU occupying status in dgx-1 (using nvidia-smi)
#!/bin/bash
function show_gpu_user {
pid=$(pstree -sg $1 | grep -Eo 'bash\([0-9]*\)' | head -1 | grep -Eo '[0-9]*');
docker ps -q | xargs docker inspect --format "{{.Name}} {{.State.Pid}}" | grep $pid | awk '{printf "%-24s", $1}';
ps aux | grep $1 | grep -v grep | awk '{ for(i=1;i<=NF;i++) {if ( i >= 11 ) printf $i" "}; printf "\n" }';
}
echo " ";
@SSARCandy
SSARCandy / interpolation_comparsion.ipynb
Last active April 12, 2017 14:26
python opencv shrink interpolation comparsion
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.