Skip to content

Instantly share code, notes, and snippets.

View lemonlatte's full-sized avatar

Jim Yeh lemonlatte

  • Taipei, Taiwan
  • 17:24 (UTC +08:00)
View GitHub Profile
@lemonlatte
lemonlatte / aggregate.js
Created April 20, 2020 03:53
Mongo Aggregation example
db.profile.aggregate([
{
"$match": {
"account_number" : "e4CHPviKRu5P6L5YQ15qYL77tfXEGua4U4maPTmzf4YwxCMA9d"
}
},
{
$unwind: "$points_of_interest"
},
{
@lemonlatte
lemonlatte / receipt5.md
Created December 22, 2019 04:13
How to make a Raspberry Pi an RTSP streamer and how to consume this?

How to make a Raspberry Pi an RTSP streamer and how to consume this?

You should perform the following steps on a new SD card. Don't mess with existing solutions. It is not worth the $5 to loose something working.

I'm used to use Raspbian, so my suggestion is to go to https://www.raspberrypi.org/downloads/raspbian/ and download the latest Raspbian Stretch Lite. Flash it to your SD card. Mine have usually 16 GB, but maybe smaller work too. I'm using Etcher on macOS, a great tool for flashing.

After successful flashing enable ssh and prepare a running Wifi configuration.

A Wifi adapter should be attached to your Pi of course.

@lemonlatte
lemonlatte / encode_hex.c
Last active November 5, 2019 12:27
encode hex
unsigned int encode_hex(char *out, size_t out_sz, uint8_t *in, size_t in_sz) {
if (in_sz*2 + 1>out_sz) {
return 0;
}
uint8_t i;
for (i = 0; i < in_sz; i++) {
snprintf(out+i*2, 3, "%02x", in[i]);
}
return in_sz*2+1;
@lemonlatte
lemonlatte / main.go
Created August 22, 2019 09:09
Minimal JSONRPC over TLS
package main
import (
"crypto/tls"
"log"
"net"
"net/rpc"
"net/rpc/jsonrpc"
)
@lemonlatte
lemonlatte / docker-compose.yaml
Created August 20, 2019 01:35
MySQL Cluster (1 master, 2 slave)
version: '2'
services:
master:
image: twang2218/mysql:5.7-replica
restart: unless-stopped
ports:
- 3306:3306
environment:
- MYSQL_ROOT_PASSWORD=master_passw0rd
- MYSQL_REPLICA_USER=replica
@lemonlatte
lemonlatte / pv.yaml
Created May 27, 2019 07:01
Create a pv to migrate the old one
kind: PersistentVolume
apiVersion: v1
metadata:
name: old-pv
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
claimRef:
@lemonlatte
lemonlatte / relay.sh
Last active May 20, 2019 09:03
Use iptables to relay a mail server
#!/bin/sh
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -R PREROUTING 1 -p tcp --dport 2587 -j DNAT --to-destination $(host my.mail.server | cut -f4 -d' '):25
if [ $? -ne 0 ]; then
iptables -t nat -A PREROUTING -p tcp --dport 2587 -j DNAT --to-destination $(host my.mail.server | cut -f4 -d' '):25
iptables -t nat -A POSTROUTING -j MASQUERADE
fi
Privacy Policy of the Bao Bao Helper
In order to receive information about your Personal Data, the purposes
and the parties the Data is shared with, contact the Owner.
Contact information
Data owner
Jim Yeh, [email protected]
寶寶助手的隱私權條款
export ETCDCTL_API=3
etcdctl --endpoints=127.0.0.1:4001 endpoint status -w json
@lemonlatte
lemonlatte / new_db.sql
Created December 14, 2018 06:12
Create a new database
CREATE DATABASE db;
CREATE USER user WITH ENCRYPTED PASSWORD 'xxxx-oooo';
\c db;
GRANT ALL PRIVILEGES ON DATABASE db TO user;
GRANT USAGE ON SCHEMA public TO user ;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO user;