Skip to content

Instantly share code, notes, and snippets.

View innermond's full-sized avatar

Gabriel Braila innermond

View GitHub Profile
@innermond
innermond / rename-numbered
Created August 31, 2015 15:51
It renames files from directories as last directory + increasing number on every folder the index is reset
#/usr/bin/bash
path=
i=0
prevname=
for file in */*/*/*.jpg; do
path="${file%/*}"
name=`basename "$path"`
if [ "$name" == "$prevname" ]; then
i=`expr $i + 1`
@innermond
innermond / pdfimage
Last active October 13, 2022 10:23
Extract images from pdf but, surprise! The images that contain alpha channels are extracted as two images. The source and the mask, as they are stored inside pdf file. This script recombine them into an one png file with given transparency
#/usr/bin/bash
# extract images from pdf at first-hand
#prefix=pict
#echo extract images from "$1"
#pdfimages -j "$1" $prefix
# IMAGES ARE SAVED SECVENTIALLY AS IMAGE AND THE NEXT IS A MASK IMAGE !!!!
declare -a files=($(ls *.ppm *.pbm))
mask=
image=
for (( i = 0; i < ${#files[*]}; i = i + 2 ))
@innermond
innermond / Minify
Created January 13, 2015 12:20
Poor man's way of minifying css files while keep us out of grunt arcanes and alike
#!/bin/bash
SRC='./src'
DIST='./dist'
CSS='css'
STYLE='style.css'
# minify css files
@innermond
innermond / resizley
Created December 18, 2014 20:26
resize last 10 jpgs
for file in $(ls *.jpg -t | head -n 11); do convert $file -resize 50% $file; done
@innermond
innermond / Maker
Created November 28, 2014 11:43
a trait that gives static factory ability to the classes parasitized by it
trait StaticFactory
{
public static function Make()
{
$args = \func_get_args();
$class = new \ReflectionClass(get_called_class());
$instance = $class->newInstanceArgs($args);
return $instance;
@innermond
innermond / xpub
Created November 21, 2014 13:56
Convert docx file to an epub file
#!/bin/bash
# $1 = path to directory where docx files are stored
dir="$1"
for dox in $1/*.docx; do
# filename with spaces replaced with underscores
doc="${dox// /_}"
# path without extension
noext=${doc%.*}
@innermond
innermond / WhiteCollapser
Created October 24, 2014 12:30
Remove all extra newlines and make the paragraphes pandoc-able
#!/bin/bash
files=$1
for file in $files; do
# first delete all empty, succesive lines
# then add an extra newline
sed -i -r ':a;/^$/{d;ba};x;s/^.+$/\n/g;p;x' "$file"
done
@innermond
innermond / OCRism
Created October 16, 2014 14:39
A picture worths a thousand words, really? Let see how many, indeed!
#!/bin/bash
# path where reside images for OCR
path=$1
filename=''
ocrized=''
home=$(pwd)
# cd $path
@innermond
innermond / insertine
Last active August 29, 2015 14:07
Insert lines into certain files. After first and before last line
#!/bin/bash
# insert text lines after first line and before last line of file
# $1 = a glob expression like */assets/*.css
# $2 = a literal to be inserted after first line
# $3 = same as above but inserted before last line
for f in $1; do
eval "sed -ri '1 s/(.*)/\1\n$2; $ s/(.*)/$3\n\1/' \"$f\""
done
@innermond
innermond / pdfeg
Created September 21, 2014 14:03
Extract a range o pages $2 - $3 from a PDF document $1 as PNG images prefixed with $4 - for quality the script saves images with high resolution and scales them down
#!/bin/bash
tempdf=$(tempfile)
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=$2 -dLastPage=$3 -sOutputFile=$tempdf $1
gs -dNOPAUSE -sDEVICE=png16m -r600 -dDownScaleFactor=3 -dBATCH -dSAFER -sOutputFile="$4-$2-%00d.png" $tempdf
rm -f $tempdf