Skip to content

Instantly share code, notes, and snippets.

View innermond's full-sized avatar

Gabriel Braila innermond

View GitHub Profile
#!/bin/bash
# install first the engine from http://mike.verdone.ca/twitter/
tweets="tweets.txt"
sleeptime=5
while read line;do
t update "$line" && sleep $sleeptime
done <$tweets
@innermond
innermond / infinite space
Created September 12, 2014 12:15
How to use cd command when traverse directories with spaces in name
#!/bin/bash
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
i=0
for dir in $(ls -d *); do
# cd to book directory
my_dirname="${dir%%}"
mydir=(cd "./$my_dirname")
${mydir[@]}
@innermond
innermond / hyphens joiner
Created September 13, 2014 19:00
A piece of sed code that rejoin words splitted by hyphens
/\-$/,/[^\-]$/{
:a
N
/\-$/ ba
s/\-\n+//g
}
@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
@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 / 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 / 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 / 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 / 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 / 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