Skip to content

Instantly share code, notes, and snippets.

View kwonghung-YIP's full-sized avatar

Kwong-Hung YIP kwonghung-YIP

View GitHub Profile
@kwonghung-YIP
kwonghung-YIP / helm-charts-repo-travis.yml
Created October 5, 2019 06:33
travis.yml for helm-charts-repo repository
language: minimal
if: branch = master
before_install:
- curl -L https://git.io/get_helm.sh | bash
- helm init --client-only
script:
- mkdir files-to-gh-pages
- echo $(pwd)
@kwonghung-YIP
kwonghung-YIP / backup-docker-secrets.sh
Created October 15, 2019 03:26
Shell script for export all secrets defined in docker swarm
#!/bin/bash
service_name="backup-all-secrets"
secret_list=( `docker secret ls --format "{{ .Name }}"` )
cmd="docker service create \
--name $service_name \
--constraint node.hostname==`hostname` "
for secret in "${secret_list[@]}"
@kwonghung-YIP
kwonghung-YIP / index.js
Created June 18, 2020 18:19
Counter sample for using react-redux
import React from 'react';
import ReactDOM from 'react-dom';
import * as serviceWorker from './serviceWorker';
import { createStore, combineReducers } from 'redux';
import { Provider, useSelector, useDispatch } from 'react-redux';
const reducer = combineReducers({
counter: (state = 0, action) => {
switch (action.type) {
case "INCR":
@kwonghung-YIP
kwonghung-YIP / index.js
Created June 21, 2020 19:47
example for react-redux-thunk
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import * as serviceWorker from './serviceWorker';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { Provider, useSelector, useDispatch } from 'react-redux';
import { Card } from 'react-bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
import thunk from 'redux-thunk';
@kwonghung-YIP
kwonghung-YIP / tag-and-push-images.sh
Created December 3, 2020 03:42
[docker-CLI] Re-tag and Re-push the images that used by running containers to your private image registry
#!/bin/bash
docker login -u <<registry login>> -p <<password>> <<user registry host>>
docker ps -a --format "{{.ID}} {{.Image}}" | grep <<your registry prefix>> | \
while read line
do
ctrid=`echo $line | awk '{print $1}'`
imgtag=`echo $line | awk '{print $2}'`
@kwonghung-YIP
kwonghung-YIP / save-img-to-tag.sh
Last active December 11, 2020 04:15
[docker -CLI] Backup all images on the docker daemon to tag file, and those images had been pull from your private registry and using by the running containers.
#!/bin/bash
bkupdir="bkup_`date +%Y%m%d_%H%M%S`"
restorefile="$bkupdir/restore.sh"
log="$bkupdir/backup.log"
mkdir $bkupdir
echo "#!/bin/bash" > $restorefile
chmod u+x $restorefile
@kwonghung-YIP
kwonghung-YIP / backup-jenkins-home.sh
Created December 14, 2020 09:36
[docker-CLI] backup the jenkins_home volume for Jenkins service in docker swarm
#!/bin/bash
bkupdir="<your backup folder>/bkup_`date +%Y%m%d_%H%M%S`"
log="$bkupdir/backup.log"
mkdir -p $bkupdir
echo "backup folder : $bkupdir"
echo "Start time : `date`" >> $log
@kwonghung-YIP
kwonghung-YIP / extract-ca-crt-from-domain
Created January 7, 2021 03:45
Extract CA cert from domain and save into Java keystore
# Inspect the Root CA Cert of your domain, and it as ca.crt
openssl s_client -connect <host>:<port> -showcerts
# Verify the cert contexnt
openssl x509 -in ca.crt -text
# Create the Java Keystore file (JKS) and import the ca.crt into it
jdk/bin/keytool -import -file ca.crt -keystore trust.jks -storepass password
# Verify the JKS file
@kwonghung-YIP
kwonghung-YIP / App.js
Created November 22, 2021 07:19
Example App.js for including mqtt.js into local expo.dev project
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
// expo install mqtt
// fix refer to mqtt.js issue: https://github.com/mqttjs/MQTT.js/issues/573
const mqtt = require('mqtt/dist/mqtt')
export default function App() {
@kwonghung-YIP
kwonghung-YIP / jmeter-bsh-example.bsh
Last active February 24, 2022 05:03
JMeter BeanShell Example to integrate with Paho Java MQTTv5
import java.nio.charset.StandardCharsets;
import org.eclipse.paho.mqttv5.client.MqttClientPersistence;
import org.eclipse.paho.mqttv5.client.persist.MemoryPersistence;
import org.eclipse.paho.mqttv5.client.MqttAsyncClient;
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions;
import org.eclipse.paho.mqttv5.client.IMqttToken;
import org.eclipse.paho.mqttv5.common.MqttSubscription;
import org.eclipse.paho.mqttv5.client.MqttCallback;