Saturday, June 2, 2018

Turn PDF to text on Mac

To turn PDF to text on Mac, first install imagemagick using homebrew. Then install tesseract using homebrew. Download and put "eng.traineddata" into tessdata directory for English text.

Then run the following command:

convert -density 300 [input.pdf] -depth 8 -strip -background white -alpha off [output.tiff]
tesseract [input.tiff] [output] -c load_system_dawg=false -c language_model_penalty_non_freq_dict_word=0.1 -c language_model_penalty_non_dict_word=0.15 -c matcher_bad_match_pad=0.20


Tuesday, September 6, 2016


Gitinspector helps you analyze git activities from your repository.
Here is one of suggested options to use (using Terminal on Mac):

python gitinspector.py -Tlrw --format=htmlembedded --file-types="cs,js,asax,ascx,asmx,aspx,cshtml,fs" -x "/lib" >netisware2.html

Saturday, January 9, 2016

Rsync revisited (for Mac OS 10.10.5 Yosemite)

Get latest rsync from https://rsync.samba.org. Download also its patches, which now are in separate file. Patch.
patch -p1
patch -p1
patch -p1
Do configure and sudo make; make install
By default it will be installed to /usr/local/bin

Then execute rsync as follows:
sudo /usr/local/bin/rsync -aHxvuPESWANXN /src /dst --progress --dry-run

a equals -rlptgoD
N preserve createtimes
H preserve hardlinks
A preserve ACLs
X preserve xattr
x don't cross file system
v verbose
u skip files that are newer on the receiver

E preserve the file's executability
S handle sparse files efficiently
W copy files whole (without delta-xfer algorithm)

P equals --partial --progress, i.e., shows progress, and don't delete partially synced files when command is interrupted (to be resumed later)

Reference
http://www.lbackup.org/developer/rsync_hfs
https://discussions.apple.com/thread/6436787?start=0&tstart=0

Friday, July 10, 2015

As follow up to the entry about initial setting of Yamaha RTX on Mac, here is how to run tftp on Mac and do a firmware update:

First, start tftp server:
sudo launchctl load -w /System/Library/LaunchDaemons/tftp.plist

Then run these commands
tftp xxx.xxx.xxx.xxx (the IP address the router)
tftp> mode binary

tftp> put rtx1100.bin exec

Then stop tftp
sudo launchctl unload -w /System/Library/LaunchDaemons/tftp.plist

Thursday, June 11, 2015

How to build OpenVCS (Telepresence) on CentOS64

Use this OpenVCS:
http://code.google.com/p/openvcs/ (redirected to https://code.google.com/p/telepresence/?redir=1, version "last updated December 2014”). This version is said to be tested on CentOS64)

Build/install on VirtualBox

Get CentOS image
http://virtualboxes.org/images/centos/
(use CentOS 6.6 minimal x86_64, which is current version in December 2014)

Build and install according to https://code.google.com/p/telepresence/wiki/Support_BuildingSourceCode

OpenSSL is not built, because current version is valid

libogg, libvorbis and libtheora are not built, since they are optional.

libfaac make failed, and ffmpeg cannot be installed without this, so:
Remove line 126 from mpeg4ip.h then build (http://stackoverflow.com/questions/4320226/installing-faac-on-linux-getting-errors)

OpenAL Soft is not built, because it is optional (for 3D audio)

openOffice is optional and not built yet

When using WebRTC from Chrome connection cannot be made due to "WS handshaking not done yet” error, so modify tsip_transport_layer.c in doubango as follows (see https://code.google.com/p/telepresence/issues/detail?id=22)

Line 367:
                case event_accepted:
                case event_connected:
                        {
                                tsip_transport_stream_peer_t* peer;
                                // find peer
                                if((peer = tsip_transport_find_stream_peer_by_local_fd(transport, e->local_fd))){
                                        // If peer already exists.. do nothing :0
                                        return  0;
                                }
                                else {
                                        TSK_DEBUG_INFO("WebSocket Peer accepted/connected with fd = %d", e->local_fd);
                                        return tsip_transport_add_stream_peer(transport, e->local_fd, transport->type, tsk_true);
                                }
                        }

Doubango needs SSL to be enabled during built, otherwise, WebRTC will be connected but ended in "not acceptable”, and telepresence log will show "Remote party requesting DTLS but it is not enabled” error (see https://code.google.com/p/doubango/wiki/Building_Source_v2_0)
OpenSSL is pre-installed on CentOS but Doubango needs header files, so install openssl-devel first:
sudo yum install openssl-devel 

Then configure doubango with SSL:
./autogen.sh && ./configure --with-ssl --with-srtp --with-speexdsp --with-ffmpeg
and then build doubango.

SSL certificate (self-signed is OK) needs to be created:
https://code.google.com/p/telepresence/wiki/Configuration_Security
So, set SSL certificate:
ssh-keygen -b 1024 -f root -t dsa
Then point setting at /usr/local/sbin/telepresence.cfg to locations of pem files created above.

Telepresence make will fail with undefined reference at libtinySAK, so edit Makefile, change this LDFLAGS line:
LDFLAGS= -L/opt/openoffice4/sdk/lib
to:
LDFLAGS= -L/opt/openoffice4/sdk/lib -WI,-rpath,/usr/lib -ldl
(see http://sourceforge.net/p/cppunit/bugs/201/)

Remove openssl-devel to prevent problems with dual installation of openssl:
sudo yum remove openssl-devel

Make sure iptables is disabled to allow connections:
sudo /etc/init.d/iptables stop
(To turn off firewall on boot, do this:
chkconfig iptables off)

Edit transport configuration entry at /usr/local/sbin/telepresence.cfg, better add ip address instead of leaving the asterisks because it seems to get 0.0.0.0 as IP address, and uncomment all transport configuration entries (see https://code.google.com/p/telepresence/wiki/Support_Testing_the_system)

Start telepresence (if —config is not specified, it does not seem to use the cfg file provided by “make samples”):
telepresence —config=/usr/local/sbin/telepresence.cfg
Then log data will be shown.

Test using WebRTC. https://code.google.com/p/telepresence/wiki/Support_Testing_the_system). Access http://conf-call.org, go to settings, set the IP address of telepresence, then call.

Tuesday, December 30, 2014

Set different language/locale to certain app on Mac

Just because my Mac default language is Japanese does not mean I like all apps to be Japanese language, especially when it is incomplete or roughly translated one. An example is Gramps.

This is how to set the language/locale to English:

$ defaults write -app Gramps AppleLanguages "(en, jp)"
$ defaults write -app Gramps AppleLocale "en_US"
$ defaults write -app Gramps AppleCollationOrder "en"

Voila, now the ugly Japanese interface is gone for the app.

Monday, December 29, 2014

Time Machine using NAS on Mavericks

Just typing this on Terminal.app does not seem to work anymore.

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

So here is how I made it to work on Mavericks.

1. Execute the usual command above:
defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

2. Create image file on local disk first because creating directly on NAS will fail
The image file naming seems important: name it [hostname]_[MACaddress] (the MAC address is without colons). So if the Mac's hostname is "mbp" and its MAC address is 12:34:56:78:9a:bc, then the file name will be mbp_123456789abc
You can check the hostname from Sharing settings.
Create the image as hard disk and of type sparse bundle. The size can be set anything, e.g., 100MB. Set volume name to arbitrary name, for example TimeMachine.

3. Copy the image file to NAS and expand it to the size you need for Time Machine, for example 300GB. Turn off Time Machine first because resizing seems to be always reset by Time Machine when it is on.
Use Disk Utilities to resize, or use hdutil from Terminal:
hdiutil resize -size 300g /Volumes/Backup/mbp_123456789abc.sparsebundle

4. Mount the image and initialize
Mount the image and initialize. The mount point, for example /Volumes/TimeMahine.

5. Set the volume as Time Machine destination
Now at this point even if you open Time Machine settings the volume won't show up. You have to set it from Terminal:
sudo tmutil setdestination /Volumes/TimeMachine

6. You are ready to start backing up using Time Machine!

Reference