Thursday, June 11, 2015

Command-line WiFi manipulation!

I found this blog post a guy made on manipulating WiFi from command line. It's self-explanatory, so I'll copy-paste it and link to it. Many thanks, Matt Crampton!!

ORIGINAL LINK

Turn off wifi on your macbook from the Mac OSX terminal command line:
networksetup -setairportpower en0 off
Turn on wifi on your macbook from the Mac OSX terminal command line:
networksetup -setairportpower en0 on
List available wifi networks from the Mac OSX terminal command line:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport scan
Join a wifi network from the Mac OSX terminal command line:
networksetup -setairportnetwork en0 WIFI_SSID_I_WANT_TO_JOIN WIFI_PASSWORD
Find your network interface name
networksetup -listallhardwareports

Tuesday, May 26, 2015

Tesseract

So you have a big PDF. Or a bunch of PDFs. And they're the kind that have text in image format, so the text is not searchable. Want to command-line OCR it? That's what tesseract allows. Awesome, right? Yeahhhh...

So, follow the steps on either of these sites to get it installed:

But the site with the most comprehensive information on the entire OCR process is:

The first two sites suggest using imagemagick to convert PDF pages to image files, but the third one suggests using ghostscript with special parameterization for optimal performance, duly justified. Ghostscript worked better for me.

The PDF->image command they recommend is:
  • gs -dSAFER -dQUIET -sDEVICE=png16m -dINTERPOLATE -dNumRenderingThreads=8 -dFirstPage=STARTPAGE -dLastPage=ENDPAGE -r300 -o image%03d.png -c 30000000 setvmthreshold -f mypdf.pdf
This tells ghostscript to convert pages in file mypdf.pdf from STARTPAGE to ENDPAGE into sequential 300dpi-resolution png files called imageXXX.png (where XXX is a 3-digit 0-padded number) using 8 simultaneous rendering threads, maximizing the amount of RAM used (to process faster). The resulting images, they find, are of good enough quality to submit to the tesseract OCR.

The actual OCR command is much simpler:
  • tesseract image001.png image001
This tells tesseract to recognize all text in image001.png, and to save the textual result into image001.txt. tesseract allows many other options, including recognition parameters and language, but I didn't really get into the details of those, so I'll omit them here.

So, follow these two steps, and you can OCR your own PDFs! Follow only the second one if your input is already in image (jpg/png/bmp) format.

Another link I found with more info on the subject:
And a list of available language models for the tesseract algorithm to use:

Ghostscript

Ghostscript is awesome. It's available on command line, it comes with Mac OS X by default, and it allows a nice range of PDF manipulations. I'd already written a post where PDF documents are joined together into a single one (See PDF Merge). Now for a slight upgrade, here's a way to grab only certain pages from a document:

gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
       -dFirstPage=22 -dLastPage=36 \
       -sOutputFile=outfile.pdf inputfile.pdf

This script will take pages 22-36 from inputfile.pdf and save them into the new file outfile.pdf. Together with PDF merging, this little technique allows us to mix and match PDF pages into new documents as we best see fit.

My thanks to this site for the great tip!

Friday, August 22, 2014

Convert Video into an Image Sequence

ffmpeg to the rescue again!!

How to convert a video into a sequence of images? Just type, with your custom parameters:

ffmpeg -i <input_video> -r <images_per_sec> %05d.png
  • <input_video> is, of course, your input video file.
  • <images_per_sec> is the image extraction rate from the video. (Sampling rate from the video, you might say). e.g. 1 would get one image per second.
  • %05d.png means "the image filenames should be five digits long, start at 00001, and have the .png extension (and format).

Honored source:

Thank you honored source!

Tuesday, July 8, 2014

Making GIFs

I'm back!

Almost 2 years later. That's ok. I found out how to make GIFs!

For this you will need:

  • imageMagick (sudo apt-get install imagemagick).
  • A bunch of JPGs.
Command!

convert -delay 42 -loop 0 *.jpg NewGif.gif


You can tweak with the -delay 42 for timing, with the -loop 0 for how many times it loops, and with the file names. Enjoy!

Saturday, October 6, 2012

.bashrc, .bash_profile

While I've learned some nice bash tricks during the past few months, I haven't really gotten to customizing it or really understanding how it works from the bottom up. .bashrc and .bash_profile, for example, are two files close to the boundary of my current understanding of bash's structure.

I don't know how they really work just yet, but as I looked for how to implement bash aliases, I bumped into these sample .bashrc and .bash_profile files, which seem to illustrate bash's ample functionality comprehensively. I'll be honest, I haven't really read even five lines of it, but it seems like a super useful bit of text. Here's the link:


The website seems to be the Linux Documentation project, so I doubt it'll be going away anytime soon. (I was considering copy-pasting its contents, but that seems a bit over-paranoid).

Key repeatssssssssssssssssssssssssssss

I bump into this occasionally, but when I do, it irks me. By default on my OS X, if I press and hold the "a" key, instead of getting a long line of a's, I get this little window:


which sucks. If I wanted to type รก, I would've known it in advance and have pressed the special Option-E + A, or configured my keyboard for Spanish-style input, or found it on a web page somewhere and plagiarized it for my shameless personal gain (as I often do for arcane characters like ☮ and ∞ ). If I wanted to type something like

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

without having to press the "a" key 81 times. I'd much prefer to instead press the "a" key, hold it for 5 seconds, and be done with it. Yes, I could do it on Terminal, but it's slow to switch to another application every time I want a specific kind of keyboard input.

So today I was browsing around, looking for a way to be able to execute binaries on the current directory, from the Terminal, by typing only their names, and not having to type in "./" at the beginning of the line (you know what I'm talking about). I haven't yet found that, but I bumped into this page:

http://mac.tutsplus.com/tutorials/terminal/10-terminal-commands-that-every-mac-user-should-know/

which among other sometimes-useful tips, taught me how to disable that sucky little key-hold window for the Mac OS X GUI:

defaults write -g ApplePressAndHoldEnabled -bool false

To be honest, I have not tested it (it requires logging off and on again), but I see no reason why it shouldn't work. Enjoy!