Skip to content

Instantly share code, notes, and snippets.

@bobzsj87
bobzsj87 / alv.py
Last active March 22, 2020 10:26
alv fast table
'''
ALV fast table: https://wira.was-luzern.ch/bereiche/kast-und-recht/kurzarbeitsentschaedigung/umfang-der-entschaedigung/
Usage python alv.py old_full_monthly_salary old_percentage(e.g. 1) new_percentage
E.g. python alv.py 10000 1 0.5
'''
import sys
max_month = 12350
def salary(orig_full, old_percent, new_percent):
@bobzsj87
bobzsj87 / index.js
Created January 9, 2020 21:06
A quick lambda call to disable all instances' detailed monitoring. Can be scheduled with CloudWatch.
const AWS = require('aws-sdk');
const ec2 = new AWS.EC2();
exports.handler = async (event) => {
let ret = await ec2.describeInstanceStatus({}).promise();
const instances = ret.InstanceStatuses.map(a => a.InstanceId);
const param = {
InstanceIds: instances,
};
ret = await ec2.unmonitorInstances(param).promise();
@bobzsj87
bobzsj87 / mix.sh
Created September 12, 2019 19:59
ffmpeg mix audio
ffmpeg -y -i kev.wav -i pointsource_noises/noise-free-sound-0001.wav -filter_complex "[0:0]volume=1.8[a];[1:0]volume=0.5[b];[a][b]amix=inputs=2:duration=first" -ar 16000 -ac 1 out.wav
@bobzsj87
bobzsj87 / reassign.json
Created June 19, 2019 19:41
2 replicas for __consumer_offsets
{"version":1,
"partitions":[
{"topic":"__consumer_offsets", "partition":0, "replicas":[0,1]},
{"topic":"__consumer_offsets", "partition":1, "replicas":[0,1]},
{"topic":"__consumer_offsets", "partition":2, "replicas":[0,1]},
{"topic":"__consumer_offsets", "partition":3, "replicas":[0,1]},
{"topic":"__consumer_offsets", "partition":4, "replicas":[0,1]},
{"topic":"__consumer_offsets", "partition":5, "replicas":[0,1]},
{"topic":"__consumer_offsets", "partition":6, "replicas":[0,1]},
{"topic":"__consumer_offsets", "partition":7, "replicas":[0,1]},
@bobzsj87
bobzsj87 / test-kafkajs-lag.js
Created June 5, 2019 08:21
Test script and results for #370 for kafkajs
/*
Purpose: to test https://github.com/tulios/kafkajs/issues/370
Setup:
Kafka 2.1 bitnami AWS image, 2 brokers, t2.micro; 1 zookeeper. Fresh install based on
https://docs.bitnami.com/aws/infrastructure/kafka/administration/create-cluster/
Test procedures:
create 4 topics.
test-one: 1 partition. 2 replcas
@bobzsj87
bobzsj87 / lambda.js
Created January 28, 2019 20:29
simple lambda to update all container instances, could be triggered by cloudwatch rules
const AWS = require('aws-sdk');
const ecs = new AWS.ECS();
exports.handler = async (event) => {
const clusters = ['your-cluster-name'];
for (let cluster of clusters){
const data = await ecs.listContainerInstances({cluster}).promise();
for (let cid of data.containerInstanceArns){
let result = await ecs.updateContainerAgent({cluster, containerInstance: cid}).promise();
console.log(result);
@bobzsj87
bobzsj87 / generate_ffmpeg_sh.py
Created December 14, 2018 13:25
Generate files to combine audios with silence
sf = open('run.sh', 'w')
for i in range(2, 41):
with open('c_{}.txt'.format(i), 'w') as f:
f.write('file c_{}.mp3\n'.format(i))
f.write('file silence.mp3\n'.format(i))
f.write('file c_{}.mp3\n'.format(i))
f.write('file silence.mp3\n'.format(i))
f.write('file c_{}.mp3\n'.format(i))
sf.write('ffmpeg -f concat -safe 0 -i c_{}.txt new/c_{}.mp3\n'.format(i, i))
sf.close()
@bobzsj87
bobzsj87 / sh1106blink.py
Last active June 11, 2018 13:08
blink using github.com/gizuone/sh1106 library
@bobzsj87
bobzsj87 / readme.MD
Last active May 24, 2018 19:13
Make customized wm8731 work on RPi 3
  1. edit /boot/config.txt and comment out dtparam=audio=on, remove comment for dtparam=i2s=on, dtparam=i2c_arm=on. Add dtoverlay=audioinjector-wm8731-audio
  2. Add snd_soc_wm8731 in /etc/modules
  3. Set GPIO25=1 (turn on audio Amp. Should turn off when Audio is not used)
  4. Turn on Output Mixer HiFi (https://github.com/raspberrypi/linux/blob/rpi-4.14.y/sound/soc/codecs/wm8731.c#L187) in amixer for speaker. Use speaker-test to verify. Volume is controled by Master (https://github.com/raspberrypi/linux/blob/rpi-4.14.y/sound/soc/codecs/wm8731.c#L161) 5 Turn on Mic (https://github.com/raspberrypi/linux/blob/rpi-4.14.y/sound/soc/codecs/wm8731.c#L171) and switch Input Mux to Mic in amixer.(https://github.com/raspberrypi/linux/blob/rpi-4.14.y/sound/soc/codecs/wm8731.c#L206) Test with arecord and aplay

Header is here: https://github.com/raspberrypi/linux/blob/rpi-4.14.y/sound/soc/codecs/wm8731.h

@bobzsj87
bobzsj87 / led.py
Created April 27, 2018 14:56
simple SPI apa102 with adafruit 8x8
import spidev
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz = 800000
#signal = [0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x15,0xff,0x11,0x11,0x11,0xff,0x00,0x00,0x00,0xff,0x11,0x11,0x00,0xff,0xff,0xff,0xff]