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 / 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 / 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 / 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 / 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 / EscPos.md
Last active November 30, 2021 14:24
Imprimiento tickets con código QR
  1. Insertar en la cabecera del sitio dentro del <head> el siguiente script: <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/esc-pos-encoder.js"></script>
  2. Luego crear una función que imprima el ticket con QR de la siguiente manera:
function ImprimeTicketConQR() {
  const img = new Image();
  const encoder = new EscPosEncoder();
  return new Promise((resolve, reject) => {
      img.src='./Factu Online_files/QR2300005.jpg';
      img.onload = () => {
          const result = encoder
@maggiben
maggiben / mapKeys.ts
Created October 4, 2021 18:49
A recursive function to map an object keys
import { isPlainObject } from '@salesforce/ts-types';
/**
* Use mapKeys to convert object keys to another format using the specified conversion function.
*
* E.g., to deep convert all object keys to camelCase: mapKeys(myObj, _.camelCase, true)
* to shallow convert object keys to lower case: mapKeys(myObj, _.toLower)
*
* NOTE: This mutates the object passed in for conversion.
*
@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