Skip to content

Instantly share code, notes, and snippets.

View jonasbjork's full-sized avatar
🇸🇪
Everyday I am shuffelin'

Jonas Björk jonasbjork

🇸🇪
Everyday I am shuffelin'
View GitHub Profile
@jonasbjork
jonasbjork / pipupgrade.sh
Created February 24, 2016 11:25
Upgrade all installed pip modules at once.
#!/usr/bin/env bash
#
# Upgrade all installed pip modules at once.
#
pip list| awk '{print $1}' | xargs pip install --upgrade
@jonasbjork
jonasbjork / update_check.sh
Created January 7, 2016 22:22
Bash script that generates email report of available updates for your Ubuntu 14.04 server
#!/usr/bin/env bash
#
# This script will generate a report of packages which needs to be upgraded
# on your system. The report will be emailed to you.
#
# Look for MAILRCPT= further down and change that to your email address
#
# You need "mailutils" and "update-notifier-common" installed on your system,
# and you need to be able to send email from the system (i.e. no firewall
# blocking SMTP)
@jonasbjork
jonasbjork / betyg.sh
Last active December 14, 2015 10:11
Betygsberäkning i Bash
#!/usr/bin/env bash
MAX=80
G=$( bc <<< "${MAX}*5/10" )
VG=$( bc <<< "${MAX}*8/10" )
BETYG=$(( ${RANDOM}%${MAX}+1 ))
echo -n "Dina poäng på tentan var ${BETYG}, ditt betyg är "
@jonasbjork
jonasbjork / zsync-osx.sh
Created December 9, 2015 14:22
zsync on OSX
wget http://ftp.gnome.org/mirror/cygwin/x86/release/zsync/zsync-0.6.2-1.tar.bz2
tar jxvf zsync-0.6.2-1.tar.bz2
cd zsync-0.6.2-1
./configure --disable-dependency-tracking --prefix=/usr/local/zsync
make
sudo make install
ln -s /usr/local/zsync/bin/zsync /usr/local/bin/zsync
ln -s /usr/local/zsync/bin/zsyncmake /usr/local/bin/zsyncmake
@jonasbjork
jonasbjork / list2arr.sh
Created October 6, 2015 10:52
Read list of rows from file, create an array in Bash
#!/usr/bin/env bash
#
# Read a file with list of elements, separated by newline
# output that list to an array
#
FIRST=true
VARNAME="varname"
echo -n "${VARNAME}='"
for a in $(< input.txt) ; do
@jonasbjork
jonasbjork / check_int.php
Created September 25, 2015 09:42
checks for integer
<?php
function check_int($str) {
if(is_int($str)) {
return abs(intval($str));
} else {
return "false";
}
}
@jonasbjork
jonasbjork / fetchtemp.py
Created August 25, 2015 16:07
Fetch temperature from thermometer and store in Sqlite3 database (RPi2)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Install and set up database:
$ sudo apt-get install python-pysqlite2 sqlite3
$ sqlite3 thermo.db
sqlite> create table thermo(sensor int, therm float, humi int, dtime int);
@jonasbjork
jonasbjork / tempnu.sh
Created August 25, 2015 16:05
Report your temperature to temperatur.nu website
#!/usr/bin/env bash
RAPPORT_URL="http://www.temperatur.nu/rapportera.php?hash=YOUR_TEMPERATUR_NU_API_KEY&t="
# My thermometer has ID 231, find yours with "tdtool -l" and replace 231 if needed.
TEMP=$(tdtool -l| grep 231 | awk '{print $4}')
RAPPORTERA=${RAPPORT_URL}${TEMP::-1}
echo ${RAPPORTERA} >> tempnu.log
curl -s "${RAPPORTERA}" >> tempnu.log
@jonasbjork
jonasbjork / checkwifi.sh
Created August 25, 2015 16:03
Check wifi connection on RPi2 and reboot if no connection.
#!/usr/bin/env bash
# Script for checking wifi connection on my headless, hidden, Raspberry Pi 2
# The idea is to reboot the RPi2 when network connection is lost, so it can come
# up again. Making administration efforts minimal.
# Crontab:
# 0,10,20,30,40,50 * * * * /home/pi/checkwifi.sh
logger -t checkwifi "Checking wifi"
# Change 192.168.0.1 to your router IP-address, or use Google DNS 8.8.8.8
@jonasbjork
jonasbjork / tellevent.php
Created August 25, 2015 15:59
Dump raw traffic from TellStick Duo to stdout
<?php
// Dump the raw traffic from TellStick Duo to stdout
$s = stream_socket_client('unix:///tmp/TelldusEvents');
while(1){
echo stream_socket_recvfrom($s,1024)."\n";
}