Skip to content

Instantly share code, notes, and snippets.

kubectl get services # List all services
kubectl get pods # List all pods
kubectl get nodes -w # Watch nodes continuously
kubectl version # Get version information
kubectl cluster-info # Get cluster information
kubectl config view # Get the configuration
kubectl describe node <node> # Output information about a node
kubectl get pods # List the current pods
kubectl describe pod <name> # Describe pod <name>
kubectl get rc # List the replication controllers
@kephin
kephin / encode.sh
Created January 8, 2020 09:41
encode/decode
echo kevin | base64 #a2V2aW4K
echo a2V2aW4K | base64 -D # kevin
@kephin
kephin / server.js
Created December 22, 2019 14:47
params/query/data in server
const express = require('express')
const app = express()
app.use(express.json()) // for parsing application/json
app.use(express.urlencoded({ extended: true })) // for parsing application/x-www-form-urlencoded
app.get('/:greet', (req, res) => {
// curl http://localhost:8080/hello\?name\=kevin
console.log('====================================')
@kephin
kephin / cancelRequest.js
Created December 22, 2019 14:39
cancel axios request
/*
<button onclick="start()">Start</button>
<button onclick="cancel()">Cancel</button>
*/
let cancelTokenSource
const start = () => {
cancelTokenSource = axios.CancelToken.source()
axios
.get('http://localhost:8080', { cancelToken: cancelTokenSource.token })
@kephin
kephin / genKeys.sh
Created October 24, 2019 08:44
Generate public/private pair keys
# openssl
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout -out public.pem
# ssh-keygen
ssh-keygen -t rsa -P "" -b 4096 -m PEM -f jwtRS256.key
ssh-keygen -e -m PEM -f jwtRS256.key > jwtRS256.key.pub
@kephin
kephin / stream.js
Created October 8, 2019 10:59
replace string through stream
// 1
let body = []
proxyRes.on('data', chunk => {
body.push(chunk)
})
proxyRes.on('end', () => {
body = Buffer.concat(body).toString()
.replace(/\/dist\/rsa-ui/g, `${MLISA_BASE_URL_PREFIX}/dist/rsa-ui`)
isTextFile(req)
? res.end(body)
@kephin
kephin / curl.md
Created June 26, 2019 09:08 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@kephin
kephin / mockDateNow.js
Created March 22, 2019 06:22
Mock Date.now
// mock Date.now
const realDateNow = Date.now
Date.now = jest.fn(() => 11421423523)
// set back
Date.now = realDateNow
@kephin
kephin / mockDate.js
Last active March 14, 2019 10:10
Mocking current time for Date
describe('...', () => {
const RealDate = Date;
function mockDate(isoDate) {
global.Date = class extends RealDate {
constructor(...args) {
if (args.length) return new RealDate(...args);
return new RealDate(isoDate);
}
};
// Start a method chain that will throw an error:
// --> foo() [catches error]
// -----> bar() [catches / rethrows error]
// --------> baz() [throws error]
foo();
function foo() {
try {
bar();