Skip to content

Instantly share code, notes, and snippets.


Shang Liang quietcricket

View GitHub Profile
# Making gif with PNG files
# Generate palette
ffmpeg -f image2 -i frame%04d.png -vf scale=900:-1:sws_dither=ed,palettegen palette.png
# Join png files using the palette generate
ffmpeg -i frame%04d.png -i palette.png -filter_complex "fps=12,scale=900:-1:flags=lanczos[x];[x][1:v]paletteuse" video.gif
quietcricket /
Created Feb 6, 2020
Add user to firebase's authentication using email and password. Please note that this is not firebase admin script to add user to work on a firebase project
import hashlib
import hmac
import base64
import secrets
import json
import os
print("Create a user account with email and the password is randomly generated.")
email = input("Email: ")
quietcricket /
Last active Dec 31, 2019
Firebase local server with livereload. Requires python_livereload
import json
from livereload import Server
from tornado.web import RedirectHandler, StaticFileHandler
settings = json.load(open('.firebaserc'))
server_url = '' % settings['projects']['default']
class NoCacheHandler(StaticFileHandler):
def set_extra_headers(self, path):
quietcricket /
Created Dec 31, 2019
Change python's working directory in script
web_dir = os.path.join(os.path.dirname(__file__), 'public')
View android_gems.txt
Snackbar: small notifications shows at the bottom
quietcricket / usbcore_parameters.conf
Last active Jun 12, 2019
Enhance USB memory and disable autosuspend
View usbcore_parameters.conf
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash usbcore.usbfs_memory_mb=1000 usbcore.autosuspend=-1"
sudo update-grub
quietcricket / esp32_ble_keyboard.ino
Last active Dec 11, 2019
Setting up esp32 as a bluetooth keyboard. The BLE specifications are really complicated. Took a long time to make this work.
View esp32_ble_keyboard.ino
Based on this gist
Minor modifications
#include <BLEServer.h>
#include <BLEDevice.h>
#include <BLEHIDDevice.h>
#include <BLE2902.h>
quietcricket /
Last active Sep 25, 2019
EC2 AMI Linux 2 Installation, with python, uwsgi, supervisor, certbot & nginx
sudo yum update
# call amazon-linux-extras to view what packages are available
sudo amazon-linux-extras install nginx1
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
# gcc and python-devel required for uwsgi
quietcricket /
Created May 11, 2018
Algorithm to check if a sudoku solution is valid
from __future__ import print_function, division
def check_sudoku(arr):
# 9 rows, 9 columns and 9 sub squares
# Each of them need to have all the digits
# Not using bit shifting
alignments = [987654321] * 27
for i, row in enumerate(arr):
for j, x in enumerate(row):
quietcricket /
Created Apr 19, 2018
Create a icns file from a 1024x1024 png file
mkdir MyIcon.iconset
sips -z 16 16 Icon1024.png --out MyIcon.iconset/icon_16x16.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_32x32.png
sips -z 64 64 Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
sips -z 128 128 Icon1024.png --out MyIcon.iconset/icon_128x128.png
sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_128x128@2x.png
sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_256x256.png
sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_256x256@2x.png
sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_512x512.png