Skip to content

Instantly share code, notes, and snippets.

View MaiLinhGroup's full-sized avatar
The percolations are imminent. No need to come in.

mailinhnguyen MaiLinhGroup

The percolations are imminent. No need to come in.
View GitHub Profile
@MaiLinhGroup
MaiLinhGroup / Makefile
Last active June 17, 2022 05:49
Example Makefile for a Python project
.PHONY: today list
objects = $(wildcard *.in)
outputs := $(objects:.in=.txt)
setup:
@pip install -r requirements.txt --no-cache-dir
@echo 'Installed all requirements to (virtual) environment'
install: add compile update check
@MaiLinhGroup
MaiLinhGroup / switch-case.py
Created August 31, 2021 13:51
Python switch case with dictionary
def week_num2dayname(i: int) -> str:
switcher = {
1: 'Monday',
2: 'Tuesday',
3: 'Wednesday',
4: 'Thursday',
5: 'Friday',
6: 'Saturday,
7: 'Sunday
}
# dictionary comprehension
dict_original = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
my_new_dict = {k:v for (k,v) in dict_original.items()}
# list comprehension
list_original = ['h', 'u', 'm', 'a', 'n']
my_new_list = [letter+letter for letter in list_original] #[expression for item in list]
print(my_new_list) # ['hh', 'uu', 'mm', 'aa', 'nn']
#! /usr/bin/env zsh
for f in *.wav; do sox --ignore-length $f ../$1/$f ; done
#!/bin/bash
echo "Assign static ip to raspberry pi:"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Choose unused IP adress not appear in following list:"
sudo arp-scan --interface=wlp4s0 --localnet
read -p "192.168.1." freeIP
rm eth0
touch eth0
#!/bin/bash
echo "Setup ssh:"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
rm ssh
touch ssh
echo "some text to enable ssh on raspbian jessie" > ssh
df -h
read -p "path to boot from sd card:" bootpath
#!/bin/bash
echo "Set up raspbian image on sd card:"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
#use df -h to discover all partitions of the sd card
#umount all partitions first before keep going
df -h
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "unmount all partitions of the sd card first"
@MaiLinhGroup
MaiLinhGroup / enable_ssh_wifi_osx.sh
Created February 4, 2019 22:21
Enable ssh and bootstrap WiFi for Raspberry Pi 3 on OSX. Make it executable with "chmod +x enable_ssh_wifi_osx.sh".
#!/usr/bin/env bash
ssh_wifi() {
touch /Volumes/boot/ssh
touch wpa_supplicant.conf
echo "country=DE" >> wpa_supplicant.conf
echo "ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev" >> wpa_supplicant.conf
echo "update_config=1" >> wpa_supplicant.conf
echo "network={" >> wpa_supplicant.conf
@MaiLinhGroup
MaiLinhGroup / setup_raspbian_osx.sh
Last active July 18, 2019 15:15
Download and install a raspbian image on a SD card for a Raspberry Pi 3 on OSX. Use "chmod +x setup_raspbian_osx.sh" to make it executable.
#!/usr/bin/env bash
# download and write image to sd card
image() {
read -p "Enter raspbian image download link: " link
if [ -n "$link" ]; then
echo "Download latest raspbian image from:" $link
else
link=https://downloads.raspberrypi.org/raspbian_lite_latest
echo "No link provided. Using default link:" $link
@MaiLinhGroup
MaiLinhGroup / wpa_supplicant.conf
Created January 15, 2019 14:46
Adding the network details to the Raspberry Pi for working in headless mode
country=DE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="NETWORK-NAME"
psk="NETWORK-PASSWORD"
}