Skip to content

Instantly share code, notes, and snippets.

@innermond
innermond / .filename-aspectRatio
Created January 24, 2018 12:15
Create the meat for images array needed for pig.js
#!/bin/bash
CRT=$PWD
cd "$1"
identify -format "{filename: '%M', aspectRatio: %[fx:(w/h)]},\n" ./*.jpg > "$CRT/data"
cd -
@innermond
innermond / .remove-wrong-images
Created January 24, 2018 11:31
Remove files that are not valid jpg
#!/bin/bash
# this script should be run by command: find . -type d -exec ./.remove-wrong-images {} \;
if [ ! -d "$1" ]; then
echo "need a directory"
exit 1
fi
cd "$1"
for f in *.jpg; do
[ -f "$f" ] || continue
@innermond
innermond / gist:9aadae1cf5007f372bc082f6035df6fa
Created January 4, 2018 15:57
timeout a forever cycle with select
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
t := time.Now().Unix()
@innermond
innermond / gist:568e9c3ab9dc2f6854ae706704f8c782
Created January 4, 2018 14:51
Walk all the way down the folder hierachy
package main
import (
"fmt"
"os"
"os/user"
"path/filepath"
)
func main() {
import (
"bufio"
"fmt"
"io"
"os"
"time"
)
func main() {
@innermond
innermond / gist:728b37117c703cccad7271c5c032b75c
Last active October 18, 2017 10:38
convert jpg or png images to webp format. you will have new webp images along old ones
find . -regex '.*\.\(jpg\|png\)$' -exec bash -c 'convert "$@" -define webp:lossless=false -quality 80 "${@%.*}".webp' _ {} \;
@innermond
innermond / gist:7ca32fec2c610065b8c05e01053dd49c
Created August 29, 2017 13:14
array_vertical - create arrays comprised of same index position elements of original arrays
function array_vertical($source) {
$keys = array_keys($source);
$arr = array_values($source);
$cut = array_map(null, ...$arr);
foreach($cut as &$el) {
$el = array_combine($keys, $el);
$el = array_filter($el, function($v) {return ! is_null($v);});
}
return $cut;
$cut=[];
@innermond
innermond / gist:80960a0d2496e1c8a2a3e5733292a8fb
Last active June 15, 2017 12:21
find files into a source directory according with a regex pattern and mass copy them to a destination directory while keeping source directory structure
find <src>/ -type f -regextype posix-extended -regex '^<pattern>$' -print0 | xargs -0i cp --parents "{}" <dest>/
@innermond
innermond / scramble.jsx
Last active May 31, 2017 09:26
change text found in text layers of psd files with lorem
var dir = new Folder('/c/temp')
var files = dir.getFiles("*.psd");
for (var i = 0; i < files.length; i++) {
var doc = app.open(files[i]);
mutate(doc)
doc.close(SaveOptions.SAVECHANGES)
}
function mutate(el)
@innermond
innermond / undoc
Last active May 25, 2017 08:37
get all links from a rtf document, stripping quotes around them
cat <path/to/rtf.document> | grep -aEo '{HYPERLINK [^}]+' | cut -d' ' -f 2 | tr -d '"'