
Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts
Kindle 4NT Bitcoin Dashboard
So after a few inspirational posts on /r/Bitcoin with photos of Pebble smart watch showing the current Bitcoin value, I've decided to hack something for my Kindle 4 Non-Touch. ;) And here's the result! Using the bitcoincharts.com charts and MtGox ticker API. All the code is available on Github, along with a how-to for setting it up. https://github.com/saironiq/kindle-to-the-moon


GridPass - printable password lookup table generator
This shell script uses LaTeX to generate a PDF with a table of randomly generated passwords in a nice tabular format. This table can be used to easily choose different, random and secure passwords for various online accounts. Such practice is effective at reducing security risks imposed by usage of insecure (what is secure?) web services (just take a look at recent password leaks from linkedin and lastfm for example). REMEMBER to always BACKUP multiple copies of the generated PDF in order to not lock yourself out of all of your accounts by losing a single sheet of paper! ;)
A nice screenshot with default options follows (./gridpass.sh OR ./gridpass.sh -c 10 -r 40 -l 8 ):
Fun fact --- this picture was generated with:
General use-case is as follows:
By having a sufficiently large amount of passwords in the table (400 by default in this script), you can also take a look at the table at public places where someone could be peeking over your shoulder - you just locate the right col and row with your eyes and type it in (however, beware of keyloggers on public PCs).
Such table could also be used as a two-factor authentication token - similar to a grid card commonly used for internet banking purposes. You just have to find a way to store the generated table on auth server and you're good to go. You can also provide your own password generator if you'd like --- by default, pwgen(1) is used.
Script has some sane options built-in (pwgen(1) as generator, 400 passwords, 8-character length, secure and without ambiguous characters), you can optionally set them via command-line options (get them with ./gridpass -h or whatever) or in ~/.gridpass (automatically generated if it doesn't exist). It outputs LaTeX source code to STDOUT if no filename argument is given or generates a PDF file with pdflatex if you provide a filename. You can also redirect STDOUT to a file and compile with your own set of commands (or do whatever else you'd like to). Also, if the columns in your configuration exceed the paper size when compiling into PDF, the script will give out a warning so you can try to reduce column count until it's OK.
GridPass can also generate a title with its "-t" command-line switch (by using LaTeX's \maketitle command). It simply gets you full name from /etc/passwd or username if full name is empty and prints it out along with password info (how many passwords are there in total and their length) and current date. It may be useful if printing table for more people, so they don't get their tables mixed up --- then you can also use the "-u [username]" parameter for specifying whose table this is. However, this title "feature" takes up quite a lot of space.
Source code is available at my github repository and distributed under GPLv3 license. Feel free to post some feedback or improvement ideas.
A nice screenshot with default options follows (./gridpass.sh
Fun fact --- this picture was generated with:
$ gs -sDEVICE=pngalpha -sOutputFile=gridtest.png -r144 gridtest.pdf
General use-case is as follows:
- you're filling a registration form, which requires you to choose a password
- randomly choose one password from the table and memorize the column and row coordinates or write them down on a piece of paper and store securely
- complete registration by entering the password you've chosen
By having a sufficiently large amount of passwords in the table (400 by default in this script), you can also take a look at the table at public places where someone could be peeking over your shoulder - you just locate the right col and row with your eyes and type it in (however, beware of keyloggers on public PCs).
Such table could also be used as a two-factor authentication token - similar to a grid card commonly used for internet banking purposes. You just have to find a way to store the generated table on auth server and you're good to go. You can also provide your own password generator if you'd like --- by default, pwgen(1) is used.
Script has some sane options built-in (pwgen(1) as generator, 400 passwords, 8-character length, secure and without ambiguous characters), you can optionally set them via command-line options (get them with ./gridpass -h or whatever) or in ~/.gridpass (automatically generated if it doesn't exist). It outputs LaTeX source code to STDOUT if no filename argument is given or generates a PDF file with pdflatex if you provide a filename. You can also redirect STDOUT to a file and compile with your own set of commands (or do whatever else you'd like to). Also, if the columns in your configuration exceed the paper size when compiling into PDF, the script will give out a warning so you can try to reduce column count until it's OK.
GridPass can also generate a title with its "-t" command-line switch (by using LaTeX's \maketitle command). It simply gets you full name from /etc/passwd or username if full name is empty and prints it out along with password info (how many passwords are there in total and their length) and current date. It may be useful if printing table for more people, so they don't get their tables mixed up --- then you can also use the "-u [username]" parameter for specifying whose table this is. However, this title "feature" takes up quite a lot of space.
Source code is available at my github repository and distributed under GPLv3 license. Feel free to post some feedback or improvement ideas.
Tags:
/bin/sh,
bash,
commandlinefu,
ghostscript,
git,
github,
gs,
latex,
linux,
password,
pdf,
png,
pwgen,
script,
security,
shell,
table,
terminal,
tex
WolframAlpha CLI interface
I've reworked one of my old shell scripts: the WolframAlpha commandline interface. This client uses the free WolframAlpha API. You can get your own API key at https://developer.wolframalpha.com/portal/apisignup.html (you need it in order to use this script as I'm not giving away my own key). After you've registered your key, put it into script's config section. Here goes a little screenshot to show you the looks of this script interface:
Hope it will be of some use to somebody ;). As always, the sources are in my Github repo.
Hope it will be of some use to somebody ;). As always, the sources are in my Github repo.
Tags:
/bin/sh,
api,
ash,
bash,
git,
github,
linux,
openwrt,
repo,
repository,
router,
script,
scripting,
scripts,
search,
shell,
suggestions,
terminal,
wolframalpha,
wolframalpha.com
ThePirateBay.se search script
This ThePirateBay.se torrent search script is based on the quite modular Torrentz.eu one I've made a while ago. You can find it on my GitHub as will be usual for all of my future scripts and stuff, so don't forget to add me to your watch list :).
This deprecates the old TPB search script.
I'll greatly appreciate any feedback, so don't hesitate to leave a comment if you'd like to. Improvement ideas are also welcome ;).
You can also modify and reuse all my scripts listed in the repo if you feel like it as they're licensed under GPLv3.
This deprecates the old TPB search script.
I'll greatly appreciate any feedback, so don't hesitate to leave a comment if you'd like to. Improvement ideas are also welcome ;).
You can also modify and reuse all my scripts listed in the repo if you feel like it as they're licensed under GPLv3.
Tags:
/bin/sh,
api,
git,
github,
linux,
pirate,
piratebay,
repo,
repository,
script,
scripting,
scripts,
search,
shell,
terminal,
thepiratebay,
torrent,
torrents,
transmission
BASH script: Generate PNG image with text from CLI
A nice little BASH script which generates a PNG image (black on white by default) from a text source (eighter from a pipe or stdin until you press CTRL+D).#!/bin/bash
if [ "$1" = "--help" ] ; then
echo -e "Usage:\
Pipe some text into $0 with filename as an optional parameter."
exit 1
fi
if [ -n "$1" ] ; then
file="$1"
else
file="cli-"`date +%s`".png"
fi
echo "Saving to: $file"
cat | convert label:@- $file
Once again inspired by commandlinefu.com:
http://www.commandlinefu.com/commands/view/9104/save-command-output-to-image
BASH script: Save unsynced data to disk
Displays amount of data waiting to be written to disk(s) and invokes sync(1) to force changed blocks to disk and update the super block.
#!/bin/bash
saved=`grep ^Dirty /proc/meminfo | sed 's/Dirty\:[[:space:]]*//g`
echo "Syncing $size of unsaved data to disk(s)."
sync
Example output:
sairon@arch-sd:~$ dirty
Syncing 84 kB of unsaved data to disk(s).
Thanks to:
http://www.commandlinefu.com/commands/view/9105/find-out-how-much-data-is-waiting-to-be-written-to-disk
My shell scripts #5 - Google dictionary API (word definitions)
This two-file google dictionary API, which returns a full definition of a given word in all its forms (noun, adjective, verb, abbreviation, ...), along with a direct link to an mp3 file containing the word spoken by a google text-to-speech api (and a lot of other useful informations).
This script is divided into two separate scripts (shell and PHP) only because it is quite hard to parse JSON strings with line-oriented text processors (sed, grep, ...you get the idea). First, the shell script gets the actual data from google, does some filtering and substitution to make it easier for the following PHP script, which then iterates through the parsed JSON string and outputs the data you want (and also adds some colour).
Don't forget to change the names and paths accordingly to suit your environment and needs.
The shell script:
This script is divided into two separate scripts (shell and PHP) only because it is quite hard to parse JSON strings with line-oriented text processors (sed, grep, ...you get the idea). First, the shell script gets the actual data from google, does some filtering and substitution to make it easier for the following PHP script, which then iterates through the parsed JSON string and outputs the data you want (and also adds some colour).
Don't forget to change the names and paths accordingly to suit your environment and needs.
The shell script:
#!/bin/ash
lang="en"
if [ "$1" = "-" ]
then
read word
else
word="$*"
word=`echo $word | sed 's/\ /\+/g'`
fi
if [ ! -n "$word" ]
then
echo Specify a word to lookup in glossary.
echo Usage:
echo " dict word"
echo "use - (dash) if reading word from stdin"
exit 1
else
wget -qO - "http://www.google.com/dictionary/json?callback=dict_api.callbacks.id100&q=$word&sl=$lang&tl=$lang&restrict=pr,de&client=te" \
| sed 's/dict_api\.callbacks.id100.//' \
| sed 's/\,\"webDefinitions.*//' \
| sed 's/\\x3cem\\x3e//g' \
| sed 's/\\x3c\/em\\x3e//g' \
| sed "s/\\\x27/\'/g" \
| php-cli /opt/scripts/gloss-json.php
fi
exit 0
And the PHP one:
$fd = fopen("php://stdin", "r");
$json = "";
while (!feof($fd)) {
$json .= fread($fd, 1024);
}
$json = $json.'}';
//var_dump(json_decode($json));
$json = json_decode($json);
$word = $json->query;
$primaries = count($json->primaries);
if ($primaries == 0) echo "Sorry, no match.\n";
for ($i = 0; $i < $primaries; $i++) {
echo "\033[1;36m" , $json->primaries[$i]->terms[0]->text , " | ", $json->primaries[$i]->terms[0]->labels[0]->text ,
" ";
if ($json->primaries[$i]->terms[1]->type == "phonetic") echo $json->primaries[$i]->terms[1]->text;
echo "\033[0m\n";
$cnt = 1;
for ($j = 0; $j < count($json->primaries[$i]->entries); $j++) {
if ($json->primaries[$i]->entries[$j]->type == "related") {
for ($l = 0; $l < count($json->primaries[$i]->entries[$j]->terms); $l++) {
echo "\033[0;36m" , $json->primaries[$i]->entries[$j]->terms[$l]->text , "\033[0m ";
echo $json->primaries[$i]->entries[$j]->terms[$l]->labels[0]->text , "; ";
}
echo "\n";
}
if ($json->primaries[$i]->entries[$j]->type == "meaning") {
echo " " , $cnt , ") " , $json->primaries[$i]->entries[$j]->terms[0]->text , "\n";
for ($k = 0; $k < count($json->primaries[$i]->entries[$j]->entries); $k++) {
echo " * " , $json->primaries[$i]->entries[$j]->entries[$k]->terms[0]->text , "\n";
}
$cnt++;
}
}
}
?>
Tags:
api,
ash,
bash,
dictionary,
glossary,
google,
linux,
openwrt,
router,
script,
scripting,
shell
My shell scripts #4 - ThePirateBay.org search API
NOTE: This script is now deprecated. Continue to the new version.
A command-line interface for ThePirateBay.org! Usage is simple:
./tpb.sh [search string]You can easily change transmission to any other torrent client (which supports adding torrents by URL via CLI). The dirty sed magic can be optimized, but it works as is, so why bother? ;) Enjoy!
![]() |
| tpb.sh script in action via PuTTY |
The code:
#!/bin/ash
search() {
q="$*"
q=`echo $q | tr ' ' '+'`
results=`wget -U Mozilla -qO - "http://thepiratebay.org/search/$q/0/7/0" \
| egrep -o '(http\:\/\/.*\.torrent)|(Size\ .*B\,)|([[:digit:]]*)' \
| sed 's///g' \
| sed 's/<\/td>//g' \
| sed 's/Size\ //g' \
| sed 's/\ \;//g' \
| sed 's/\,//g' \
| sed 's!http://torrents.thepiratebay.org!!g' \
| sed ':a;N;$!ba;s/\n/\ /g' \
| sed 's!\ \/!\n\/!g' \
| sed 's/MiB\ /M\ /g' \
| sed 's/GiB\ /G\ /g' \
| sed 's/KiB\ /K\ /g' \
| cat`
IFS=$'\n'
longest=0
for line in $results
do
length=`echo "$line" | awk '{print $1}' | wc -L`
if [ $length -gt $longest ]
then
longest=$length
fi
done
nth=0
for line in $results
do
whites=""
length=`echo $line | awk '{print $1}' | wc -L`
nth=`echo "$nth + 1" | bc -l`
spaces=`echo "$longest + 1 - $length" | bc -l`
for i in `seq 1 $spaces`
do
whites=`echo "$whites "`
done
torrent=`echo $line | awk '{print $1}' | sed 's!\/[[:digit:]]*\/!!' | sed 's!\.[[:digit:]]*\.TPB\.torrent!!' | sed 's/_/\ /g'`
size=`echo $line | awk '{print $2}'`
size=`printf '%10s' "$size"`
seeds=`echo $line | awk '{print $3}'`
seeds=`printf '%5s' "$seeds"`
peers=`echo $line | awk '{print $4}'`
peers=`printf '%5s' "$peers"`
if [ $nth -lt 10 ]
then
nth=" $nth"
fi
echo -e "$nth $torrent$whites\033[1;34m$size\t\033[1;31m$seeds\t\033[1;32m$peers\033[0m"
done
}
download() {
echo -n "Download? "
read num
if [ $num -eq 0 ]
then
exit 1
else
i=0
for line in $results
do
i=`echo "$i + 1" | bc -l`
if [ $i -eq $num ]
then
link=`echo "$line" | awk '{print $1}'`
echo "Downloading torrent file."
transmission-remote -a "http://torrents.thepiratebay.org$link"
echo "Torrent added."
exit 0
fi
done
fi
}
search $*
download
unset IFS
exit 0
My shell scripts #2 - WHOIS search
This time, we're going to get some informations about domains through WHOIS servers. All this via CLI interface and without the ubiquitous "whois" command (which is not available for my CPU architecture in OpenWrt package repository and I'm too lazy to cross-compile it myself). Used programs: "netcat", "sed", "grep".
The whois-servers.net server automatically redirects you to the WHOIS server responsible for the supplied TLD, so you don't have to remember them (and it also simplifies this script).
The whois-servers.net server automatically redirects you to the WHOIS server responsible for the supplied TLD, so you don't have to remember them (and it also simplifies this script).
#!/bin/ash
if [ ! -n "$1" ]
then
echo "Usage:"
echo " $0 domain.tld"
exit 1
fi
tld=`echo $1 | sed 's/\/.*//' | grep -o '[[:alpha:]]*$'`
echo "$1" | netcat -T $tld.whois-servers.net 43
echo
exit 0
My shell scripts #1 - Wikipedia search
I will publish my creations here, just in case someone finds them useful. My scripts are made for the ash shell, so they should work in most of the other shells. I run them on my OpenWrt router with 400MHz CPU and 32MB RAM with no problems :).
The first one I'm going to publish is a Wikipedia search script, requiring only "dig" and "sed" programs. Usage is fairly simple, just type:
The script automatically replaces all spaces with underscores. And now the actual code:
The first one I'm going to publish is a Wikipedia search script, requiring only "dig" and "sed" programs. Usage is fairly simple, just type:
$ ./wiki.sh hello world
The script automatically replaces all spaces with underscores. And now the actual code:
#!/bin/ash
if [ ! -n "$1" ]
then
echo "What are you searching for?"
echo "Usage:"
echo " $0 keyword"
exit 1
fi
q=`echo $* | sed 's/\ /\_/g'`
dig +short txt $q.wp.dg.cx | sed 's/\"\ \"//'
exit 0
Subscribe to:
Posts (Atom)




