Skip to content

Instantly share code, notes, and snippets.

View justinmklam's full-sized avatar

Justin Lam justinmklam

View GitHub Profile
@justinmklam
justinmklam / scp-cheat-sheet.sh
Last active January 14, 2020 22:32
SCP example commands for local/server file transfer.
# Copy a file from local to server
scp ~/rebels.txt [email protected]:~/revenge
# Copy a directory from server to local
scp -r [email protected]:~/revenge ~/revenge
# Copy multiple files from server to local
scp [email protected]:"revenge/*.txt" ~/revenge/
# Copy file between two servers
@justinmklam
justinmklam / setup-raspberry-pi-headless-wifi.md
Created November 19, 2019 17:38
Setup wifi on headless pi

In the boot partition of the SD card, create an empty ssh file:

touch ssh

To setup the wifi, create wpa_supplicant.conf and add the following:

country=US
class ReadLine:
def __init__(self, s):
self.buf = bytearray()
self.s = s
def readline(self):
i = self.buf.find(b"\n")
if i >= 0:
r = self.buf[:i+1]
self.buf = self.buf[i+1:]
@justinmklam
justinmklam / flask-port80-without-sudo.md
Last active June 21, 2024 19:59
Run a flask app on port 80 without sudo.

Flask apps are bound to port 5000 by default. To bind it to port 80, you would need to change the port as follows:

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80, debug=True)

And to run it:

var FeedReader = {
settings: {
feedItemsCount: 10,
url: 'http://someurl.com/news/feed/',
feedListing: $('div#feedListing'),
loadFeedButton: $('a.loadFeed')
},
init: function () {
@justinmklam
justinmklam / install-nodejs-linux.md
Last active October 19, 2019 17:14
Instructions to install Node.js on linux

Background

Although sudo apt install nodejs works, it's not recommended because there will be permission issues when trying to install packages globally (ie. npm install -g sass).

A better way to install Node.js is to use Node Version Manager (nvm).

Installing with NVM

# Check the github page for the latest version
@justinmklam
justinmklam / fix-random-brightness-msi-linux.md
Last active October 17, 2019 16:39
Fixes brightness randomly changing on MSI laptops. Source: https://askubuntu.com/a/808785

This seems to be a common problem on most MSI laptops, including my own GP62 6QF Leopard Pro. Supposedly, one way to fix it would be to update your BIOS, however, this didn't work for me.

I managed to fix this by adding this to /usr/share/X11/xorg.conf.d/10-quirks.conf:

Section "InputClass"
  Identifier "Spooky Ghosts"
  MatchProduct "Video Bus"
  Option "Ignore" "on"
EndSection
@justinmklam
justinmklam / print-to-systemd.py
Created October 8, 2019 23:43
Snippet to print python output to systemd
import sys
print('Hello')
sys.stdout.flush()
# Output will be:
# Nov 27 19:31:09 rpi python[334]: Hello
@justinmklam
justinmklam / generate-changelog.sh
Last active February 6, 2020 06:41
Bash script to generate a changelog
#!/usr/bin/env bash
# Generates a changelog between tagged releases. Collects commits of pull requests, major, and bugfix tags
repository_url="https://bitbucket.org/MYPROJECT/MYREPO"
function generate_changelog() {
previous_tag=0
for current_tag in $(git tag --sort=-creatordate)
do
if [ "$previous_tag" != 0 ];then
@justinmklam
justinmklam / basic-systemd-example.md
Last active October 29, 2020 22:27
Basic example to create a systemd service
  1. Create a file like below (ie. myscript.service). Change Description=, User=, and ExecStart=.
[Unit]
Description=My Service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always