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 / xmas_tree.py
Created April 8, 2016 10:10
Print one christmas tree on terminal using star char
space = " "
j = 1
print "Weihnachtsbaum in Python 2.x"
start = 1
stop = 6
incr = 2
for i in range(start,stop,incr):
if i < stop - 1 :
print space*j ,"*" * i
j -= 1
@MaiLinhGroup
MaiLinhGroup / setup_login_ssh_linux.sh
Last active February 4, 2019 22:28
Scripts to first set up sd card with latest raspbian image, then assign static ip to, enable ssh (disabled by default since jessie) and finally copy ssh key for convenient login. Please make scripts executable with chmod and execute with sudo permission.
#!/bin/bash
echo "Insert sd card in pi and boot first:"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
sudo arp-scan --interface=wlp4s0 --localnet
read -p "enter pi adress" pi
ssh-copy-id -i ~/.ssh/id_rsa.pub $pi
ssh $pi
@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"
}
@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 / 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
#!/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"
#!/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 "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
#! /usr/bin/env zsh
for f in *.wav; do sox --ignore-length $f ../$1/$f ; done
# 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']