Skip to content

Instantly share code, notes, and snippets.

View maggiben's full-sized avatar

Benjamin maggiben

  • Frávega
  • Argentina
View GitHub Profile
@maggiben
maggiben / garden-guardian.md
Last active August 18, 2024 03:09
Remote Watering System Setup

Remote Watering System Setup

Requisites

  1. Raspberry PI Zero 2W (any PI should work ok)
  2. nodemcu-32s
  3. USB OTG Cable, Power Supply, etc...

Preparation

  1. Flash the OS into the SD card (32gb is plenty) (Config: Username, Wifi and SSH)
  2. Connect the i2c RTC module to the rpi
@maggiben
maggiben / service.md
Last active August 17, 2024 17:31
remove dark images systemd daemon

Dark image remover daemon

Intended to be used to clean timelapse pictures

Requirements

  1. Python 3
  2. OpenCV library (cv2)
  3. NumPy library (numpy)

Install python virtual env sudo apt install python3-venv

@maggiben
maggiben / base.sh
Last active July 31, 2024 15:51
Base sensor monitor
#!/bin/bash
# Get the size of /snapshots
SNAPSHOT_SIZE=$(du -hs /snapshots 2>/dev/null | awk '{print $1}')
SNAPSHOT_TOTAL=$(ls | grep *.jpg | wc -l 2>/dev/null)
echo "[snapshots]"
echo "size: $SNAPSHOT_SIZE"
echo "total: $SNAPSHOT_TOTAL"
# Get the available space on the root partition
@maggiben
maggiben / toISO8601.js
Created May 1, 2023 03:47
To ISO8601 date string with locale offset
// Ardiono Date https://adafruit.github.io/RTClib/html/class_date_time.html#a50502a3a29409c6c2507638779df1a9d
let now = new Date();
// correct time zone offset for generating iso string
now.setMinutes(now.getMinutes() - now.getTimezoneOffset())
console.log(now.toISOString());
@maggiben
maggiben / linux.js
Last active October 14, 2022 05:29
Read the contents of /proc/stats and print the % of cpu utilization (tested on ubuntu) (go to http://www.linuxhowtos.org/System/procstat.htm to find what the meaning of each field in that file is)
var fs = require('fs');
// An object to store our data
var stat = {
cpu: {
user: 0,
nice: 0,
system: 0,
idle: 0,
iowait: 0,
@maggiben
maggiben / minimustache.functional.js
Last active February 23, 2022 15:02
Mini Mustache
/*
Bare bones template engine
*/
const hydrate = function(template, scope) {
if (
template.constructor === String &&
template.length &&
scope.constructor === Object &&
Object.keys(scope).length
) {
@maggiben
maggiben / getNodeVersion.ts
Created January 3, 2022 02:01
Get Node Version
export function getNodeVersion(): { major: number; minor: number; patch: number } {
const version = process.version.match(/(\d+)\.(\d+)\.(\d+)/);
const [major, minor, patch] = ensureArray(version)
.slice(1)
.map((match) => parseInt(match as string, 10));
return {
major,
minor,
patch,
};
@maggiben
maggiben / promise-pool.ts
Last active December 18, 2021 14:09
Runs a pool of max concurrency promises, as soon as on of the promises in the pool is resolved another can enter
export default async function scheduler<T, K>(
maxconnections: number,
items: K[],
functor: (item: K) => Promise<T>
): Promise<Array<T | undefined>> {
const workers: Array<T | undefined> = [];
for await (const result of runTasks<T>(maxconnections, tasks(items, functor))) {
workers.push(result);
}
return workers;
@maggiben
maggiben / youtubeUtils.ts
Created December 5, 2021 13:41
Youtube RexExp utilities
const playlistId = new RegExp(/(?:http|https|)(?::\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{12,})[a-z0-9;:@#?&%=+\/\$_.-]*/)
const videoId = new RegExp(/(?:http|https|)(?::\/\/|)(?:www.|)(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[a-z0-9;:@#?&%=+\/\$_.-]*/)
const getYouTubeId = (youTubeUrl: string): string | undefined => {
const regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/
var match = youTubeUrl.match(regExp)
if (match && match[2].length == 11) {
return match[2]
}
return undefined
@maggiben
maggiben / release.md
Last active November 30, 2021 17:54
Releasing YTKIT
  1. Modify the version in package.json to X.X.XX
  2. git commit -m "chore: release vX.X.XX"
  3. git tag -a vX.X.XX HEAD -m "release vX.X.XX"
  4. git push (make sure you setup your push to also push the tags) if not use git push --tags
  5. Update all deps with yarn upgrade --latest