Categories
linux machine learning Solutions

Cross-compile latest Tensorflow (1.5+) for the Nvidia Jetson TK1

Been looking around for a solid resource on how to get Tensorflow to run on the Jetson TK1. Most what I found was how to get TF 0.8 to run, which was the last TF version to allow usage of cuDNN 6 that is the latest version available for the TK1.
The TK1 is an aging platform with halted support, but it is still a cheap option for high-powered embedded compute. Unfortunately, being so outdated it’s impossible to get the latest and greatest of DNN to work on the CUDA GPU on the TK1, but we can certainly use the CPU!
So a word of disclaimer – this compiled TF version will not use the GPU, just the CPU. However, it will let you run the most recent NN architectures with the latest layer implementations.
Cross compilation for the TK1 solves the acute problem of space on the device itself, as well as speed of compilation. On the other hand it required bringing up a compilation toolchain, which took a while to find.
I am going to be assuming a Ubuntu 16.04 x86_64 machine, which is what I have, and really you can do this in a VM or a Docker container just as well on Windows.

Categories
code programming python Solutions Web

A script to scrape PDFs from a page using Python+Mechanize

A friend asked me for a way to download all the PDFs from a page, and I made this simple script with Python and Mechanize. It’s very straightforward…
It does hack the user agent, which is not nice. So use at your discretion.

Categories
code Solutions Web

Bootstrap3 fluid container with custom width sidebar

I was looking for a way to get a fluid container live side-by-side with a custom width sidebar.
A custom width sidebar can’t be achieved with a Bootstrap column, and is a total mess to get right with floats if you then need a fluid container to get a grid system for the main section.
So, here’s one solution:

JSFiddle: https://jsfiddle.net/6sfog80k/

Categories
Android ffmpeg linux Music Networking Solutions Stream

FFMpeg with Lame MP3 and streaming for the Arduino Yun

So, I’ve been trying to stream audio off of a USB microphone connected to an Arduino Yun.
Looking into it online I found some examples using ffserver & ffmpeg, which sounded like they could do the trick.
However right from the start I’ve had many problems with playing the streams on Android and iOS devices.
Seems Android likes a certain list of codecs (http://developer.android.com/guide/appendix/media-formats.html) and iOS like a different set of codecs (Link here), but they do have on codec in common – good ol’ MP3.
Unfortunately, the OpenWRT on the Arduino Yun has an ffmpeg build which does not provide MP3 encoding… it does have the MP3 muxer/container format, but streaming anything other then MP3 in it (for example MP2, which the Yun-ffmpeg does have) simply doesn’t work on the Android/iOS.
From experiments streaming from my PC a ffmpeg/libmp3lame MP3 stream, it looks like the mobile devices are quite happy with it – so I will need to recompile ffmpeg with Lame MP3 support to be able to stream it.

Categories
linux Solutions

Struggles with creating Linux Live USB on Mac OSX

SO I’ve been trying to create a bootable live USB of some linux distro on the Mac and failed consistently. That is – until I found a magical solution!

Categories
linux Solutions

Tailing the output of multiple files in Linux

This is a quick post to show a trick to tail multiple files, while showing the filename in the beginning of the line
What I needed was a way to grep multiple logs for an exception. But doing “tail -f *.log | grep exception” only let me see the exception, but I didn’t know which log file to look in
I have found this guide, and altered the script and added

  1. Printing the file name in the beginning of each line
  2. Padding spaces after the file name (you can alter the minimal length in the ALIGN variable

Anyway – here’s the script. Hope you find it useful

#!/bin/bash
# When this exits, exit all back ground process also.
trap 'kill $(jobs -p)' EXIT
ALIGN=31
# iterate through the each given file names,
for file in "$@"
do
        LENGTH=`echo ${file} | wc -c`
        PADDING=`expr ${ALIGN} - ${LENGTH}`
        PAD=`perl -e "print ' ' x $PADDING;"`
        # show tails of each in background.
        tail -f $file | sed "s/^/${file}${PAD}:/g"  &
done
# wait .. until CTRL+C
wait
Categories
Android Mobile phones Solutions

A Creative way to bypass Pattern lock on Android

Let me start putting everything on the table – this post will describe how I eventually managed to unlock an unrooted, non-Google account linked Samsung Galaxy Mini Plus (GT-5570I) device without ADB support. There are a lot of guides on how to bypass this pattern lock on Android (and I will provide some links), but the purpose of this post is to show how looking for creative ways to do this can come handy

So a friend gave me a locked device. This device had no Google account linked to it (which prevented me from bypassing the lock with that account), there was no root or ADB access via recovery, and the USB debugging option was disabled.

I found this guide here, which states some commands you can type in ADB shell and should deactivate the pattern lock. So – How do I get ADB access on that phone?

Categories
code linux programming Solutions tips

Reading a directory in C++ (Win32 & Posix)

Just a snippet of code if someone out there needs it. I keep coming back to it, so I thought why not share it…

#include <iostream>
#ifndef WIN32
#include <dirent.h>
#endif
using namespace std;
void open_imgs_dir(char* dir_name, std::vector<std::string>& file_names) {
	if (dir_name == NULL) {
		return;
	}
	string dir_name_ = string(dir_name);
	vector<string> files_;
#ifndef WIN32
//open a directory the POSIX way
	DIR *dp;
	struct dirent *ep;
	dp = opendir (dir_name);
	if (dp != NULL)
	{
		while (ep = readdir (dp)) {
			if (ep->d_name[0] != '.')
				files_.push_back(ep->d_name);
		}
		(void) closedir (dp);
	}
	else {
		cerr << ("Couldn't open the directory");
		return;
	}
#else
//open a directory the WIN32 way
	HANDLE hFind = INVALID_HANDLE_VALUE;
	WIN32_FIND_DATA fdata;
	if(dir_name_[dir_name_.size()-1] == '\\' || dir_name_[dir_name_.size()-1] == '/') {
		dir_name_ = dir_name_.substr(0,dir_name_.size()-1);
	}
	hFind = FindFirstFile(string(dir_name_).append("\\*").c_str(), &fdata);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (strcmp(fdata.cFileName, ".") != 0 &&
				strcmp(fdata.cFileName, "..") != 0)
			{
				if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				{
					continue; // a diretory
				}
				else
				{
					files_.push_back(fdata.cFileName);
				}
			}
		}
		while (FindNextFile(hFind, &fdata) != 0);
	} else {
		cerr << "can't open directory\n";
		return;
	}
	if (GetLastError() != ERROR_NO_MORE_FILES)
	{
		FindClose(hFind);
		cerr << "some other error with opening directory: " << GetLastError() << endl;
		return;
	}
	FindClose(hFind);
	hFind = INVALID_HANDLE_VALUE;
#endif
	file_names.clear();
	file_names = files_;
}

Enjoy
Roy.

Categories
ffmpeg Recommended Solutions tips Windows scripting

Useful ImageMagick and FFmpeg shortcuts for Win SendTo menu

Hello
Quickly sharing some useful scripts I’ve “developed” over the summer to cope with some image resizing / video ripping / transcoding, etc.
Instead of using some specialized GUI software for transcoding I thought why not simply put useful options in the Windows file browser “Send To…” context menu. That way I can right-click the file I want to work with and just send it to some tool to do the job.
Here it is…

Categories
linux Raspberry Pi Recommended school Solutions tips

The Raspberry Pi is Here

A few months back I placed an order for a raspberry pi. For those who don’t know what it is, it is a really cool project which is basically a computer for 35$ (Shipping for me almost doubled it, but that’s to be expected). It is a board, which as 256MB Ram, SD-Card slot, 2 USB Slots, an RCA Slot for analog video, and a headphone jack for analog audio.
It is originally a project for schools, to help today’s kids get started with (python, but not only) programming.
To be exact with what the project guys are describing it:
The Raspberry Pi is a credit-card sized computer board that plugs into a TV and a keyboard. It’s a miniature ARM-based PC which can be used for many of the things that a desktop PC does, like spreadsheets, word-processing and games. It also plays High-Definition video.
Here are some FAQs

The OS of this board is stored on an SD Card. I have bought a class 10 16gb SD Card off of eBay for this purpose.
So few days ago, the board arrived! I finally found myself playing with it, and it’s so much fun
Here are some common suggestions for usages: