--- /dev/null
+format() {
+ if [ $1 -lt 100 ]; then # round down <.1 kb
+ printf '000K'
+ elif [ $1 -lt $((10**3)) ]; then
+ printf '0%sk' $(echo "scale=1;$1 / 10^3" | bc -l)
+ elif [ $1 -lt 9950 ]; then
+ printf '%sk' $(round `echo "$1 / 10^3" | bc -l` 1)
+ elif [ $1 -lt 99500 ]; then
+ printf '0%sk' $(round `echo $1 / 10^3 | bc -l` 0)
+ elif [ $1 -lt 999500 ]; then
+ printf '%sk' $(round `echo $1 / 10^3 | bc -l` 0)
+ elif [ $1 -lt 1050000 ]; then
+ printf '%sm' $(echo `round $(echo "$1 / 10^7" | bc -l) 1`*10 | bc -l)
+ elif [ $1 -lt 9950000 ]; then
+ printf '%sm' $(round `echo "$1 / 10^6" | bc -l` 1)
+ elif [ $1 -lt 99500000 ]; then
+ printf '0%sm' $(round `echo "$1 / 10^6" | bc -l` 0)
+ elif [ $1 -lt 999500000 ]; then
+ printf '%sm' $(round `echo $1 / 10^6 | bc -l` 0)
+ elif [ $1 -lt 9950000000 ]; then
+ printf '%sg' $(round `echo $1 / 10^9 | bc -l` 1)
+ elif [ $1 -lt 99500000000 ]; then
+ printf '0%sg' $(round `echo $1 / 10^9 | bc -l` 0)
+ elif [ $1 -lt 999500000000 ]; then
+ printf '%sg' $(round `echo $1 / 10^9 | bc -l` 0)
+ else
+ printf 'fast'
+ fi
+}
+
+round() {
+ echo $(printf %.$2f $(echo "scale=$2;(((10^$2)*$1)+0.5)/(10^$2)" | bc))
+}
+
+for x in {1000..10000}; do format $(( $x * 10 )); done
+
--- /dev/null
+#!/bin/bash
+
+# smbbind.sh share mountpoint
+# smbbind.sh "//SERVER/SHARE" "/mnt/somewhere"
+
+check_every=30 #Seconds
+timeout_after=5 #Seconds
+restart_after=30 #Seconds
+
+hide_path=~/.smbbind/
+cifs_opts="rw,cache=strict,username=nt_username,password=nt_password,domain=nt_domain,uid=0,noforceuid,gid=0,noforcegid,file_mode=0755,dir_mode=0755,nounix,serverino,rsize=61440,wsize=57344,actimeo=60,_netdev"
+
+share="$1"
+bind_mountpoint="$2"
+
+function clean {
+ #Umount bindfs, next umount cifs, then exit.
+ echo [..] Cleaning...
+ #The only open handle opened on the cifs share should be the bindfs one.
+ echo [..] forcing umounting bindfs on "$bind_mountpoint"
+ kill -9 $bindfs_pid
+ umount -f "$bind_mountpoint"
+ echo [OK] Done.
+ # Umounted bindfs, cifs should umount without problems
+ echo [..] Forcing umounting cifs on "$cifs_mountpoint"
+ umount -f "$cifs_mountpoint"
+ umount -l "$cifs_mountpoint"
+ echo [OK] Done cleaning.
+}
+
+function finish {
+ echo exiting...
+ clean
+ trap exit INT TERM EXIT
+ exit
+}
+
+trap finish INT TERM EXIT
+
+#Prepare environment
+ mkdir $hide_path &>/dev/null
+ cifs_mountpoint=$hide_path/$(echo $bind_mountpoint|tr '/' '_')
+ mkdir -p $cifs_mountpoint &>/dev/null
+ mkdir -p $bind_mountpoint &>/dev/null
+
+while true ; do
+
+ #Mount things:
+ echo [..] mounting cifs "$share" on "$cifs_mountpoint"
+ if timeout 10 mount.cifs "$share" "$cifs_mountpoint" -o $cifs_opts ; then
+ echo [OK] mounted cifs "$share" on "$cifs_mountpoint"
+
+ echo [..] mounting bind "$cifs_mountpoint" on "$bind_mountpoint"
+ bindfs "$cifs_mountpoint" "$bind_mountpoint"
+ #Getting the pid of bindfs is tricky.
+ bindfs_pid=$(ps -eo pid,args|grep bindfs |grep "$cifs_mountpoint" |grep "$bind_mountpoint" |cut -d " " -f 1)
+ echo [OK] mounted bind "$cifs_mountpoint" on "$bind_mountpoint"
+
+ #Check them
+ echo [OK] Start Main check cycle, whill check every $check_every seconds...
+ while true ; do
+ if ! timeout -k 1 $timeout_after ls "$bind_mountpoint" &>/dev/null ; then
+ echo no answer from bindfs for "$bind_mountpoint"
+ clean
+ break
+ #else
+ #echo Share is alive
+ fi
+ sleep $check_every
+ done
+
+ else
+ echo [!!] Cannot mount "$share" on "$cifs_mountpoint"
+ fi
+
+ echo [..] Waiting $restart_after seconds: $(date)
+ sleep $restart_after
+
+done
--- /dev/null
+for fgbg in 38 48 ; do # Foreground / Background
+ for color in {0..255} ; do # Colors
+ # Display the color
+ printf "\e[${fgbg};5;%sm %3s \e[0m" $color $color
+ # Display 6 colors per lines
+ if [ $((($color + 1) % 6)) == 4 ] ; then
+ echo # New line
+ fi
+ done
+ echo # New line
+done
+
+exit 0
--- /dev/null
+#! /bin/bash
+
+AUTHUSER=admin
+AUTHPASS=$1
+curl -s gateway/DashBoard.asp -u $AUTHUSER:$AUTHPASS | sed -n 's/.*Internet-status2" class="Condition-\(\w*\)".*/\1/gp'
+
--- /dev/null
+/* rgbtobgr565 - convert 24-bit RGB pixels to 16-bit BGR565 pixels
+
+ Written in 2016 by Glenn Randers-Pehrson <glennrp@users.sf.net>
+
+ To the extent possible under law, the author has dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+ See <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+ Use with ImageMagick or GraphicsMagick to convert 24-bit RGB pixels
+ to 16-bit BGR565 pixels, e.g.,
+
+ magick file.png -depth 8 rgb:- | rgbtobgr565 > file.bgr565
+
+ Note that the 16-bit pixels are written in network byte order (most
+ significant byte first), with blue in the most significant bits and
+ red in the least significant bits.
+
+ ChangLog:
+ Jan 2017: changed bgr565 from int to unsigned short (suggested by
+ Steven Valsesia)
+*/
+
+#include <stdio.h>
+int main()
+{
+ int red,green,blue;
+ unsigned short bgr565;
+ while (1) {
+ red=getchar(); if (red == EOF) return (0);
+ green=getchar(); if (green == EOF) return (1);
+ blue=getchar(); if (blue == EOF) return (1);
+ bgr565 = (unsigned short)(red * 31.0 / 255.0) |
+ (unsigned short)(green * 63.0 / 255.0) << 5 |
+ (unsigned short)(blue * 31.0 / 255.0) << 11;
+ putchar((bgr565 >> 8) & 0xFF);
+ putchar(bgr565 & 0xFF);
+ }
+ }
--- /dev/null
+#!/bin/sh
+
+#
+# update-blocklist-2.sh
+# Download a list of blocked domains and pass to dnsmasq
+#
+
+target='blank' # IP to resolve blocked domains to
+configfile=/etc/dnsmasq.conf
+
+
+# List server specification
+listurl="http://pgl.yoyo.org/adservers/serverlist.php?hostformat=nohtml&showintro=0"
+extrasfile='/etc/blacklist' # Add additional entries here
+reloadcmd='/etc/init.d/dnsmasq restart'
+tmpfile="/tmp/.adlist.$$"
+tmpconf="/tmp/.dnsmasq.conf.$$"
+fetchcmd="/usr/bin/curl "$listurl" -o "$tmpfile""
+
+$fetchcmd
+
+# Add additional entries
+[ -f "$extrasfile" ] && cat $extrasfile >> $tmpfile
+
+# Check temp file
+if [ ! -s $tmpfile ]; then
+ echo "temp file '$tmpfile' either doesn't exist or is empty; quitting"
+ exit
+fi
+
+# save old config (excluding address entries)
+if [ -f "$configfile" ]; then
+ cat $configfile | grep -v "address=" > $tmpconf
+fi
+
+while read line; do
+ echo "address=/${line}/${target}" >> $tmpconf
+done < $tmpfile
+
+mv $tmpconf $configfile
+$reloadcmd
+rm $tmpfile
+exit