Skip to content

Instantly share code, notes, and snippets.

Avatar

Shang Liang quietcricket

View GitHub Profile
View ffmpeg-commands.sh
# 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
quietcricket / add_firebase_user.py
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
View add_firebase_user.py
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
quietcricket / firebase_livereload.py
Last active Dec 31, 2019
Firebase local server with livereload. Requires python_livereload
View firebase_livereload.py
import json
from livereload import Server
from tornado.web import RedirectHandler, StaticFileHandler
settings = json.load(open('.firebaserc'))
server_url = 'https://%s.web.app/__/' % settings['projects']['default']
class NoCacheHandler(StaticFileHandler):
def set_extra_headers(self, path):
@quietcricket
quietcricket / change_working_directory.py
Created Dec 31, 2019
Change python's working directory in script
View change_working_directory.py
web_dir = os.path.join(os.path.dirname(__file__), 'public')
os.chdir(web_dir)
View android_gems.txt
Snackbar: small notifications shows at the bottom
@quietcricket
quietcricket / usbcore_parameters.conf
Last active Jun 12, 2019
Enhance USB memory and disable autosuspend
View usbcore_parameters.conf
/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash usbcore.usbfs_memory_mb=1000 usbcore.autosuspend=-1"
sudo update-grub
@quietcricket
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 https://gist.github.com/sabas1080/93115fb66e09c9b40e5857a19f3e7787
Minor modifications
*/
#include <BLEServer.h>
#include <BLEDevice.h>
#include <BLEHIDDevice.h>
#include <BLE2902.h>
@quietcricket
quietcricket / ec2_ami_linux_2_installation.sh
Last active Sep 25, 2019
EC2 AMI Linux 2 Installation, with python, uwsgi, supervisor, certbot & nginx
View ec2_ami_linux_2_installation.sh
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
quietcricket / sudoku_checker.py
Created May 11, 2018
Algorithm to check if a sudoku solution is valid
View sudoku_checker.py
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
quietcricket / iconutil_icns.sh
Created Apr 19, 2018
Create a icns file from a 1024x1024 png file
View iconutil_icns.sh
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