Skip to content

Instantly share code, notes, and snippets.

@megasaturnv
megasaturnv / watchNewsbeuter.sh
Last active January 8, 2018 11:18
One-liner to check newsbeuter for updates every 30 seconds. If an unread item apears, it will alert the user with an audible bell and open newsbeuter. https://github.com/akrennmair/newsbeuter http://www.newsbeuter.org/
#!/bin/sh
#Megasaturnv 2017-06-08
while true; do sleep 30; newsbeuter -x reload -x print-unread | grep -q "^0 unread articles" && echo -n . || (echo -e "\a"; newsbeuter) ; done
@megasaturnv
megasaturnv / digitalReadDebounce.ino
Last active September 1, 2022 10:32
Arduino simple digitalRead with software debounce
//Megasaturnv 2017-07-05
//Arduino simple digitalRead with software debounce
//Digital read an pin with software debounce. Pin should be set as: pinMode(pin, INPUT_PULLUP) in setup().
//Arduino ATMEGA328P (and some other ATMEL chips) have internal pull-up resistors. Pin is active when connected to GND
//Projects where pins are active high (with pull down resistors) should modify lines 7 and 11 below, as indicated
//This function will return true if input is active for at least 50ms and then released. The function will return false if input is not active
bool digitalReadDebounce(int pin) {
if (digitalRead(pin) == LOW) { // <- Change to '== HIGH' if pin is active high
delay(50);
@megasaturnv
megasaturnv / parseRssFeed.sh
Last active October 16, 2023 07:29
Shell script / one-liner to parse and display an rss feed. May require tweaking for RSS feeds without newlines or where <title> and <description> are on separate lines to their text.
#!/bin/sh
#Megasaturnv 2017-07-28
#Url of the RSS feed
RSS_URL=""
##Commented version:
#Download the rss feed
curl --silent "$RSS_URL" | \
#Only match lines with 'title>' or 'description>'
@megasaturnv
megasaturnv / daysUntilChristmas.sh
Last active January 8, 2018 11:15
Shell one-liner to echo / print the number of days until christmas (or any other arbitrary date)
#!/bin/sh
#Megasaturnv 2017-07-28
echo $(($(date -d 25-Dec +%-j) - $(date +%-j))) days until christmas!
@megasaturnv
megasaturnv / tmuxAutoAttach.sh
Last active January 8, 2018 10:45
Automatically attach to a tmux session if one exists
#!/bin/sh
#Megasaturnv 2017-11-17
(tmux ls | grep -q "attached" && echo "[Info] You are already attached to a tmux session") || tmux attach
@megasaturnv
megasaturnv / customTmux.sh
Last active January 8, 2018 10:44
Setup a custom tmux session
#!/bin/sh
#Megasaturnv 2017-11-17
#useful examples: /usr/share/doc/tmux/examples
SESSION="tmux_$USER"
tmux -2 new-session -d -s $SESSION
#0 Setup a window for general use
tmux rename-window -t $SESSION:0 "General"
@megasaturnv
megasaturnv / checkRcloneVersion.sh
Last active January 8, 2018 11:41
Check Rclone version. Checks version from https://rclone.org/downloads/ and compares it to current version in checkRcloneVersion_current.txt, which needs to be updated after a new version of rclone is installed
#!/bin/sh
#Megasaturnv 2018-01-08
# Uncomment to create checkRcloneVersion_current.txt file:
# echo v1.38 > checkRcloneVersion_current.txt
# Add following line to crontab (crontab -e) to check once a week (every Monday at 21:21)
# 21 21 * * 1 ./checkRcloneVersion.sh
LOCAL_VERSION="$(cat checkRcloneVersion_current.txt)"
@megasaturnv
megasaturnv / mjpeg_Snapshot.php
Last active December 13, 2019 10:33
PHP motion jpeg mjpeg snapshot single frame with or without http auth. No temporary file needed
<?php
//Megasaturnv 2018-01-12
$camurl="http://192.168.1.100:8081/"; // Mjpeg URL
//$camurl="http://username:[email protected]:8081/" // HTTP Auth mjpeg URL (optional)
$boundary="--BoundaryString"; // $boundary = The boundary string between jpegs in an mjpeg stream
//NOTE: $boundary changes between mjpeg stream providers. For example, https://github.com/Motion-Project/motion uses '--BoundaryString'. https://github.com/ZoneMinder/ZoneMinder uses '--ZoneMinderFrame'. To find out $boundary for your stream you will need to save 1 or more frames of the mjpeg and open it with a text editor. --<boundary string> should be visible on the first line
$f = fopen($camurl, "r"); // Open mjpeg url as $f in readonly mode
$r = ""; // Set $r to blank variable
if($f) {
@megasaturnv
megasaturnv / mjpeg_Snapshot_img_tag.php
Last active January 17, 2018 16:24
PHP motion jpeg mjpeg snapshot single frame with or without http auth. Puts image in <img> tag with no temp file
<?php
//Megasaturnv 2018-01-16
$camurl="http://192.168.1.100:8081/"; // Mjpeg URL
//$camurl="http://username:[email protected]:8081/" // HTTP Auth mjpeg URL (optional)
$boundary="--BoundaryString"; // $boundary = The boundary string between jpegs in an mjpeg stream
//NOTE: $boundary changes between mjpeg stream providers. For example, https://github.com/Motion-Project/motion uses '--BoundaryString'. https://github.com/ZoneMinder/ZoneMinder uses '--ZoneMinderFrame'. To find out $boundary for your stream you will need to save 1 or more frames of the mjpeg and open it with a text editor. --<boundary string> should be visible on the first line
$f = fopen($camurl, "r"); // Open mjpeg url as $f in readonly mode
$r = ""; // Set $r to blank variable
if($f) {
@megasaturnv
megasaturnv / webcam_snapshot.php
Last active January 16, 2018 14:42
Display snapshot from usb webcam camera /dev/video0 on a webpage. No temp file. Uses avconv command
<?php
//Megasaturnv 2018-01-16
header("content-type: image/jpeg");
// Change this resolution to match your camera \/
echo passthru("avconv -f video4linux2 -i /dev/video0 -vframes 1 -s 1920x1080 pipe:.jpg 2>/dev/null");
?>