Skip to content

Instantly share code, notes, and snippets.

View dardo82's full-sized avatar
🏠
Working from home

Michele Venturi dardo82

🏠
Working from home
View GitHub Profile
@dardo82
dardo82 / periscope.sh
Last active August 19, 2016 02:36
Save Periscope Videos
#!/bin/zsh
cd "${0%/*}/../conf/url/"
for user in $(cat ../users.list); do
TWEETS=$(t search timeline -d -l user "#Periscope:" | grep -v " RT @")
OLDIFS=$IFS; IFS=$'\n'
for tweet in $(echo $TWEETS); do
DATE=$(echo $tweet | cut -d\ -f2-6)
OLD_LC_ALL=$LC_ALL; export LC_ALL="POSIX"
SEC=$(($(date +%s) - $(date -j -f ' %b %e %H:%M ' "$DATE" +%s)))
@dardo82
dardo82 / cart-prod.sh
Last active January 26, 2016 03:44
Operations with sets
#!/bin/zsh
join -1 2 -2 2 <(echo ${${1//,/\\n}//({|})/}) <(echo ${${2//,/\\n}//({|})/})|gsed 's/^ /(/;s/ /,/;s/$/)/;s/\n/,/'|gsed -z 's/\n/,/g;s/^/{/;s/,$/}\n/'
@dardo82
dardo82 / cam-light-action.sh
Last active September 14, 2018 23:34
FW webcam USB light
#!/bin/zsh
# Use an USB light to let FW webcam see
PATH=$PATH:/usr/local/bin
UHCOPTS=$(uhubctl | awk '{ text=text"\n"$0; if ($0~/hub/) text=$0; if (text~/power$/) { print text; text="" } }' \
| awk -F',| |:' -v ORS=" " '{ print $5 }' | awk '{ print "-p "$2" -l "$1 }')
if [ -n "$UHCOPTS" ]; then
uhubctl -a 0 ${=UHCOPTS}
DEVNAME="iSight"; DEVGUID=$(system_profiler SPCameraDataType | awk -v dev="$DEVNAME:" -F':|x|-' '{ if ($0~dev) n=NR; if (NR==n+3 && NR!=3) print $3 }')
@dardo82
dardo82 / automator2shell.sh
Last active November 13, 2016 21:28
Automator to SH script
#!/bin/zsh
# Convert Apple Automator "Run Shell Script" action to actual shell script
NAME="${${1##*/}%.*}.sh"
CDWF="$1/Contents/document.wflow"
touch $NAME
chmod +x $NAME
awk -F'<|>' '/bin\/.*sh/{print "#!"$3; exit}' $CDWF > $NAME
@dardo82
dardo82 / chromium-ud.sh
Last active January 3, 2016 19:20
Chromium Updater
#!/bin/zsh
APP="${${0##*/}%-*}; OST="mac"; DAZ="${APP/ium/e}-$OST.zip"
URL="https://commondatastorage.googleapis.com/$APP-browser-snapshots/${(C)OST}"
ASS="$(curl -s $URL/LAST_CHANGE)"
ADA="${$(brew cask info $APP|awk -v ORS=/ '/^(\/| )/{print $1}')%/*}"
SCM="$(awk -F'#|}' '/#/{print $3}' $ADA/Contents/Info.plist)"
if [ $SCM -lt $ASS ]; then
cd $TMPDIR; pkill ${(C)APP}
curl -O $URL/$ASS/$DAZ; unzip $DAZ
mv -frv ${DAZ%.*}/${$ADA##*/} $ADA
@dardo82
dardo82 / radiorosa.sh
Last active March 28, 2016 06:57
Rec RadioRosa stream
#!/bin/sh
# Download n seconds of RadioRosa stream
gtimeout ${1}s curl http://onair15.xdevel.com:8100/ > radiorosa.mp3
# gtimeout ${1}s curl http://onair15.xdevel.com:8072/ > radiorosa.m4a
@dardo82
dardo82 / tvl.sh
Last active March 28, 2016 06:57
Rec TVL stream
#!/bin/zsh
MM3U8="live-04.viewer.dacast.com/i/dclive_1@104057/master.m3u8"
TJSON="http://services.dacast.com/token/i/b/28193/c/34004.json"
TOKEN="$(print $(curl -s "$TJSON" | awk -F'["]' '{print $6}'))"
IM3U8="$(curl -s "$MM3U8""$TOKEN" | awk '/m3u8/')"
TSSEG="$(curl -s "$IM3U8" | awk '/ts/{match($0,/([0-9]+)_/,a);\
sub(/([0-9]+)_/,"["a[1]"-"a[1]+9"]_");print $0;exit}')"
curl --limit-rate 100k "$TSSEG" >> tvl.ts
@dardo82
dardo82 / collatz-graph.sh
Last active July 28, 2019 15:46
Conjecture proof scripts
#!/usr/bin/env zsh
zmodload zsh/mathfunc
setopt extended_glob
BN="${${0##*/}%%.*}"
{
NC=(1)
echo "strict digraph collatz {"
for n in {2..$1}; do
if [ ! ${NC[(r)$n]} ]; then
@dardo82
dardo82 / primes.sh
Created January 28, 2016 05:43
Primes < n
#!/bin/zsh
# Print the prime numbers less than n.
# for n in {1..$1}; do gfactor $n; done | awk -F'[: ]' '{if($3~$1)print $3}'
for n in {1..$1}; do gfactor $n; done | awk -F'[ ]' 'NF==2{printf $2" "}'
@dardo82
dardo82 / Stream-STEnt.sh
Last active February 26, 2016 03:15
Stream StarTrek Ent
#!/bin/sh
# Stream an FLV to AppleTV
# using AirPlay mirroring
airplay-mirror start
URL="guardarefilm.tv/serie-tv-streaming/3506-star-trek-enterprise.html";EP=${1/x/_}
open -W -a vlc $(curl $URL|sed -n "s/embed/mobile/;s/-640x360.html/.mp4/;/sd-$EP\"/p"|cut -d\" -f8)
airplay-mirror stop