Skip to content

Instantly share code, notes, and snippets.

View vthily's full-sized avatar

Ly vthily

  • NTU
  • Singapore
View GitHub Profile
@vthily
vthily / app.vue
Created May 31, 2021 05:29
Remove the echoes when enable audio recording on web-browser
<script>
export default {
components: {},
data () {},
created (){},
mounted (){},
methods: {
async prepare () {
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)()
let source
@vthily
vthily / main.js
Created June 1, 2021 12:20
Download zip file with NodeJS and AdmZip
const express = require('express')
const app = express()
const axios = require('axios')
const fs = require('fs')
const multiparty = require('multiparty')
var AdmZip = require('adm-zip')
app.use(express.static('dist'))
app.use(express.json())
app.disable('x-powered-by')
@vthily
vthily / app.vue
Last active June 5, 2021 14:40
Send data from server (NodeJS) and client (VueJS) via socket.io
<template>
</template>
<script src="http://localhost:8000/socket.io/socket.io.js"></script>
<script>
const io = window.io = require('socket.io-client');
/* socket.on('announcements', function() {
console.log('Got announcement');
// code to handle the token goes here
io.emit('feedback', 'This is the feedback from client');
@vthily
vthily / deployment.yaml
Last active October 30, 2021 09:28
Sample application without helm
apiVersion: v1
kind: Secret
metadata:
name: sample-app-secret
namespace: sample-namespace
type: Opaque
data:
SECRET_KEY: "super duper secret"
---
apiVersion: apps/v1
@vthily
vthily / sample.py
Created October 21, 2021 15:21
Flask API application
from flask import Flask
from flask_restful import Api, Resource, reqparse, fields
#from flask_httpauth import HTTPBasicAuth
from mlogging.mlogger import logger
from heartrateToSI import calculateStressIndex
import pprint
app = Flask(__name__, static_url_path="")
@vthily
vthily / normalizeAcronym.py
Last active June 9, 2022 03:13
Group the single characters (they are adjacent in order) into meaningful acronyms
#!/usr/bin/python3
import functools
def normalizeAcronyms(inputStrInWords):
# Step1: Add extra space to prevent concatenate with previous word
inputStrInWords = list(map(lambda a: a+' ' if len(a) > 1 else a, inputStrInWords))
# Step2: Remove the underscore, eg: c_d_a, l_p_a, etc.
inputStrInWords = list(map(lambda a: a.replace('_', '').upper() if '_' in a else a, inputStrInWords))
@vthily
vthily / voting-app.yaml
Last active September 15, 2022 03:19
Sample voting application for k8s
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-vote-back
spec:
replicas: 1
selector:
matchLabels:
app: azure-vote-back
template:
sentencepiece==0.1.97
simplejson==3.16.0
six==1.12.0
SoundFile==0.10.3.post1
sox==1.4.1
torch==1.12.1
torchaudio==0.12.1
torchvision==0.13.1
typeguard==2.13.3
ffmpy==0.3.0
@vthily
vthily / daemonset-scaledown.md
Created November 28, 2022 06:59 — forked from ragul28/daemonset-scaledown.md
k8s Trick to Scale down daemonset to zero
  • Scaling k8s daemonset down to zero
kubectl -n kube-system patch daemonset myDaemonset -p '{"spec": {"template": {"spec": {"nodeSelector": {"non-existing": "true"}}}}}'
  • Scaling up k8s daemonset
kubectl -n kube-system patch daemonset myDaemonset --type json -p='[{"op": "remove", "path": "/spec/template/spec/nodeSelector/non-existing"}]'
@vthily
vthily / falsehoods-programming-time-list.md
Created March 1, 2024 01:34 — forked from timvisee/falsehoods-programming-time-list.md
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).