Skip to content

Instantly share code, notes, and snippets.

@rolfen
rolfen / crawler.js
Last active March 29, 2024 20:00
Javascript Console (in-browser) based crawler
let getElement, crawlDom, getCats, save, rowify; // functions
let urlBase, pages; // input data
// config
let waitInterval = 500; // how much to wait between fetching pages
// selectors
let catRe = /\{\s*productcategories\s*\:\s*(\[\s*\{[\s\S]*\}\s*\])\s*\}/m;
let selectors = {
'name' : '#showroomTopContentDiv .showroom-header h1',
@rolfen
rolfen / archive.bash
Last active February 29, 2024 11:49
Extract previews and metadata from original photos and videos. Archive and backup.
#!/bin/bash
# Import and organize into subfolders by date taken (YYYY/MM/DD)
scriptname=`basename "$0"`
if [[ $# -ne 2 ]]; then
echo "Usage: $scriptname /source/dir /archive/dir"
else
(cd "$2"; exiftool -progress -ext MTS -ext ARW -ext ORF -ext xmp -r -m -d %Y/%m/%d "-Directory<DateTimeOriginal" "$1")
@rolfen
rolfen / 00 Ideas and notes
Last active August 24, 2023 23:45
Ideas and notes
Related to Linux
@rolfen
rolfen / funcs.php
Last active July 26, 2023 00:21
A library of utility of generally useful PHP functions (filesystem, images, ini, text manipulation...). Outdated version of PHP.
<?php
// ============ strings ================
function smart_truncate($string, $limit, $break=" ", $pad="...") {
// truncates string to the first $break after $limit characters, then adds $pad to the end
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
// return with no change if string is shorter than $limit
$string = strip_tags($string);
@rolfen
rolfen / flatten.md
Created April 26, 2022 11:00
Flatten subdirectories (Linux)

This

find -type f -exec mv {} ./ \;

turns this

/folder
@rolfen
rolfen / _README.md
Last active April 9, 2021 05:33
Resume a dd operation with a check

This little script resumes an interrupted dd copy at a given offset.

Before resuming, it rolls back (the amount of roll-back is OVERLAP_SIZE * CHUNK) then calculate the checksum of the overlap on both files to make sure that they are valid images of each other.

The checksums have to be checked manually by the operator (todo: automate).

@rolfen
rolfen / CheatCheet.md
Last active February 4, 2021 20:43
MyArchive

Warning These are for educative purposes (examples, tips, etc.). Do not blindly execute them.

Fix double separator in hash-file (double or more space -> single space)

cat meta/hash-file.list | sed -E 's/^(\S+)\s{2,}(\S.+)$/\1 \2/'

Fix windows newlines in file

@rolfen
rolfen / gist:17bf252d9fbf6d8e0d771269d9690ca3
Created September 3, 2016 18:37
Deconstruct URL (quick regex)
window.location.href.match(/^([^/]+):\/\/([^/:]+):?([1-9]*)\/([^?]*)\??(.*)$/)
Example output:
["http://127.0.0.1:1337/projects/sd?sdflkj&jh", "http", "127.0.0.1", "1337", "projects/sd", "sdflkj&jh"]
That is: full match, protocol, host, port, path (relative to root), query string
Todo: test for bugs.
@rolfen
rolfen / DeutscheWörter.md
Last active January 24, 2021 09:26
German Words
De En
störrischer stubborn
bemühunngen efforts
vorübergehend temporarily
verdrangen to displace
Einschätzung assessment
fällig due
Gegenstand object
Reichweite reach

Setting up multiple user write permission to WWW directory

addgroup www-admin
adduser joe
adduser www-admin joe
setfacl -R -m g:www-admin:rwx /var/www
setfacl -R -m -d g:www-admin:rwx /var/www
chmod -R g+s /var/www