Skip to content

Instantly share code, notes, and snippets.

@peihsinsu
peihsinsu / gce-snapshot.sh
Created September 19, 2014 13:38
GCE daily scheduling snapshot backup
#!/bin/bash
# Environments
export PATH=/root/google-cloud-sdk/bin:$PATH
# Daily create snapshot for "backup_path" listed disks
# And remove snapshot 1 week old before
# Create snap date
export DT=`date +%Y%m%d`
@peihsinsu
peihsinsu / get-cpu-info.js
Created September 25, 2014 13:28
Get CPU info restful
var http = require('http');
var os = require('os');
http.createServer(function(req, res){
res.writeHead(200, {'Content-Type':'application/json'});
res.end(JSON.stringify(os.cpus()));
}).listen(3000);
@peihsinsu
peihsinsu / socketio-express4-server.js
Created October 2, 2014 15:03
express4 compacted socket.io server and client
/**
* Socket server
* file: web.js
*/
var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
server.listen(80);
@peihsinsu
peihsinsu / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@peihsinsu
peihsinsu / gcp.commands.md
Last active September 3, 2015 01:16 — forked from qrtt1/gcp.commands.md
qrtt1提供的target pool bug操作流程

create

gcloud compute instances create my-unmanaged-instance --zone asia-east1-b
gcloud compute target-pools create my-pool --region asia-east1
gcloud compute forwarding-rules create my-rule --target-pool my-pool --region asia-east1
gcloud compute target-pools add-instances my-pool --instances my-unmanaged-instance --zone asia-east1-b
gcloud compute instance-templates create my-template
gcloud compute instance-groups managed create my-group --base-instance-name mgroup --size 1 --template my-template --target-pool my-pool --zone asia-east1-b
@peihsinsu
peihsinsu / cpu.js
Created December 27, 2015 10:35 — forked from bag-man/cpu.js
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores
@peihsinsu
peihsinsu / nodejs-bigquery-sample.js
Created June 5, 2016 11:33
peihsinsu/bigquery module full example
var bq = require('bigquery')
, fs = require('fs')
, prjId = 'mitac-cp300'; //you need to modify this
bq.init({
json_file: '/Users/peihsinsu/.gcpkeys/mitac-cp300/mitac-cp300-e75b19c172ba.json'
});
var sql = {
aaa: 'SELECT count(*) FROM [cp300.books2] LIMIT 1000'
@peihsinsu
peihsinsu / bigquery_sample.gs
Last active September 2, 2016 10:04
BigQuery sample for Apps Script
function runQuery() {
var projectId = 'sunny-573';
var request = {
query:
"SELECT FORMAT_UTC_USEC(metadata.timestamp) as time, structPayload.rpitemp as pi_temp " +
"FROM [sunny-573:linkerlab.rpitemp_simon_project_LYDvUZWJJtOPxRERAAAC_20160902@-3600] " +
"WHERE metadata.labels.value = 'linker-log-gateway' ORDER BY structPayload.ctime desc LIMIT 3000"
};
@peihsinsu
peihsinsu / remove-docker.sh
Last active June 10, 2018 04:17
full remove docker
systemctl stop docker
apt remove docker docker.io docker-ce docker-engine -y
apt autoremove docker docker.io docker-ce docker-engine -y
rm /etc/init/docker
rm /etc/init.d/docker
rm -rf /var/lib/docker
rm -rf /etc/docker
rm -rf /etc/default/docker
mv /var/lib/dpkg/info/docker-engine.* /tmp/
apt update -y
@peihsinsu
peihsinsu / k8s-minion-eviction-limit.sh
Last active August 22, 2018 14:34
fix kubernetest minion eviction issue
mkdir -p /etc/systemd/system/kubelet.service.d/
cat > /etc/systemd/system/kubelet.service.d/20-node-eviction.conf <<EOF
Environment="KUBELET_EXTRA_ARGS=--eviction-hard=memory.available<500Mi --system-reserved=memory=1Gi"
EOF