Skip to content

Instantly share code, notes, and snippets.

View quietcricket's full-sized avatar

Shang Liang quietcricket

  • Singapore
View GitHub Profile
@quietcricket
quietcricket / abspath_pyinstaller.py
Created August 24, 2023 02:27
pyinstaller can package a python app into a single executable file. When this executable file runs, it's first extracted into a temporary location then the python script is called. The usual loading of files with relative path would not work. The following code is found online to work around this issue.
def abspath(filename):
# looking for magic word _MEIPASS
bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
return os.path.abspath(os.path.join(bundle_dir, filename))
@quietcricket
quietcricket / pip_cert_fix.md
Created August 24, 2023 02:21
Fix pip install certificate error

For Windows 💻 only

Because the computer is behind a corporate firewall, with additional firewall software installed, pip install always fails and gives a CERTIFICATE_VERIFY_FAILED error. It's either the access to the to the cert file is blocked or the cert is not recognized.

The best way to solve this problem I found so far is to add a pip.ini file in ~/AppData/Roaming/pip/pip.ini with the following content

[global]
@quietcricket
quietcricket / transfer-domain-from-aws-to-gandi.md
Created October 17, 2022 01:57
Transfer Domain from AWS to Gandi
  • Unlock domain in AWS Route53
  • Copy authentication code
  • Start transfer process in Gandi
  • Paste authentication code
  • AWS will send a approval link to the email address registered for the domain
  • If the approval link is not triggered, domain transfer will fail
  • The last step is very important
@quietcricket
quietcricket / ffmpeg-commands.sh
Created January 28, 2021 08:45
FFMPEG Commands
# 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 February 6, 2020 08:36
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
quietcricket / firebase_livereload.py
Last active December 31, 2019 07:49
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 = 'https://%s.web.app/__/' % settings['projects']['default']
class NoCacheHandler(StaticFileHandler):
def set_extra_headers(self, path):
@quietcricket
quietcricket / change_working_directory.py
Created December 31, 2019 03:15
Change python's working directory in script
web_dir = os.path.join(os.path.dirname(__file__), 'public')
os.chdir(web_dir)
Snackbar: small notifications shows at the bottom
@quietcricket
quietcricket / usbcore_parameters.conf
Last active June 12, 2019 18:51
Enhance USB memory and disable autosuspend
/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 December 11, 2019 17:56
Setting up esp32 as a bluetooth keyboard. The BLE specifications are really complicated. Took a long time to make this work.
/*
Based on this gist https://gist.github.com/sabas1080/93115fb66e09c9b40e5857a19f3e7787
Minor modifications
*/
#include <BLEServer.h>
#include <BLEDevice.h>
#include <BLEHIDDevice.h>
#include <BLE2902.h>