detect.cpp____Projects_mocavo-rnd_handwriting_detection__-_VIM__vim_

Recently, I was working on some basic Object Recognition and was having trouble figuring out how to get started with OpenCV2 in Ubuntu. There was a lot of disparate advice and documentation across the web, and after spending a little bit of time stitching it together, came up with these 3 steps to getting started with OpenCV2 development using C++ in Ubuntu.

Step One: Installation

Run the following command to install OpenCV2 and all dependencies:

1
sudo apt-get install libcv2.3 libcvaux2.3 opencv-doc libcv-dev libcvaux-dev

Step Two: Header

Much of the documentation that I came across didn’t account for the distinction between OpenCV and OpenCV2, so the headers often looked like this:

1
2
#include <cv.h>
#include <highgui.h>

After some Googling, I found the following to be correct:

1
#include <opencv2/opencv.hpp>

Step Three: Compiling

Compilation also requires linking the OpenCV2 libraries. There is a lot of different documentation on how to do this, however the following seemed to be the most foolproof to me:

1
g++ hello.cpp -o file `pkg-config opencv --cflags --libs`

Step Four: Profit!

That’s it! Keep in mind, I am fairly new to OpenCV, so this may not be the best or most accurate path to getting started, but it worked for me and I felt I should share it.

Read more

Screenshot_5_9_13_5_04_PM-2

I’m a big fan of Git. It is a super easy-to-use version control and source code management system. Before I came to Git, though, I used Mercurial, and there were three commands that I missed. Through a lot of Googling, I came across three Git aliases that have changed everything for me: incoming and outgoing.

Usage

Incoming

Command:

1
git incoming

The Incoming command will return a nicely formated list of incoming commits, the next time you do a pull.

1
2
3
$ git incoming
621d0eb - Developer Name -  (origin/master, origin/HEAD) Commit Message - 2 days ago
31d6367 - Developer Name -  Commit Message - 2 days ago

Outgoing

Command:

1
git outgoing

The Outgoing command will return a nicely formated list of outgoing commits, the next time you do a push.

1
2
3
$ git outgoing
9a0af47 - Zachary Flower -  (HEAD, master) Update Message - 5 seconds ago
b900493 - Zachary Flower -  .htaccess removed from application folder - 6 weeks ago

Setup

To add the aliases, put the following in your .gitconfig file (typically located in your home directory):

1
2
3
[alias]
    incoming = !(git fetch --quiet &amp;&amp; git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' ..origin/master)
    outgoing = !(git fetch --quiet &amp;&amp; git log --pretty=format:'%C(yellow)%h %C(white)- %C(red)%an %C(white)- %C(cyan)%d%Creset %s %C(white)- %ar%Creset' origin/master..)

Read more

Recently, I purchased a Hauppauge WinTV-HVR 950Q Hybrid TV Stick for the purpose of watching and recording television on my Mac Mini. After I purchased the stick, it took some Googling, and a lot of trial and error, before I realized that the Windows-designed USB TV Tuner only worked using EyeTV in Mac OSX. Fast-forward another $80 later and I was comfortably watching and recording television on my Mac Mini. Now, for most people, this would be more than enough functionality to last a lifetime, but unfortunately for me, I am not most people. My end-result with buying this TV tuner was to automatically save all recordings into my Plex Library, so I can watch everything from one comfortable, and usable, place. I did a lot of searching, but none of the solutions were really right for me, so I decided to write my own.

As I started writing my EyeTV-to-Plex workflow, I had a few rules I wanted to follow:

  1. The recorded television shows needed to be playable in Plex
  2. The recorded television shows needed to be put into a separate Recorded TV Shows directory that Plex watches
  3. The Recorded TV Shows Directory needs to have an easy-to-follow directory structure and file naming convention so Plex can easily download album art and tag the shows
  4. All duplicated files need to be deleted

Now, as I started to dig into how to do this, the first thing I discovered was that EyeTV stores all files in a proprietary .eyetv file format. Attempting to convert these files directly using HandBrake or FFmpeg was fruitless, so in a last ditch effort at discovering some information, I took to the command line and, upon doing a simple ls, I found that the .eyetv extension was just a package, rather than an encrypted file. The contents of this package were incredibly useful to me. The most important was the video file, in MPEG format. Second most important was the .eyetvp file, which is an XML file containing all the show’s metadata (season number, show title, episode number, and episode name). With these two files, I had everything I needed to start writing my workflow.

Step One

I popped open Automator and began working on my Plexify workflow. The first step was to sort through a list of provided files and select only the files that had the eyetv extensions, but skipping the Live TV Buffer file (no need to send that to Plex).

02-filter-finder-items

Step Two

Once we had these files, we needed to select the folder contents (remember, the .eyetv file is just a folder) and send it to an AppleScript for sorting and filtering.

Read more

I was recently working with Overscroll, a jQuery plugin by Azoff Design, and was very impressed with the implementation. After a little playing around, though, I started running into an issue that the plugin didn’t seem to support. The main problem was that I needed the ability to scroll in both directions (rather than the only-vertical or only-horizontal directions allowed by the plugin) using the mouse wheel. I did some quick Googling to see if anyone had solved this particular problem before, but after not finding anything, I decided to take a crack at it myself. The plugin is very well written, which made updating it a piece of cake. The section of code that handled mouse wheel scrolling was only taking into account the “delta” of the scroll, regardless of direction. After a bit of research, I found that you could get wheelDeltaX and wheelDeltaY, in addition to wheelDelta, from the mouse wheel. The result of the (very few) updates I had to make is below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// handles mouse wheel scroll events
wheel = function (event) {

    // prevent any default wheel behavior
    event.preventDefault();

    var data = event.data,
    options = data.options,
    sizing = data.sizing,
    thumbs = data.thumbs,
    wheel = data.wheel,
    flags = data.flags, delta, deltax, deltay,
    original = event.originalEvent;

    // stop any drifts
    flags.drifting = false;

    // calculate how much to move the viewport by
    // TODO: let's base this on some fact somewhere...
    if (original.wheelDelta) {
        delta = original.wheelDelta / (compat.prefix === 'o' ? -120 : 120);
    }

    if ( original.wheelDeltaX) {
        deltaX = original.wheelDeltaX / (compat.prefix === 'o' ? -120 : 120);
    }
   
    if ( original.wheelDeltaY) {
        deltaY = original.wheelDeltaY / (compat.prefix === 'o' ? -120 : 120);
    }
   
    if (original.detail) {
        delta = deltaX = deltaY = -original.detail / 3;
    }
   
    delta *= options.wheelDelta;
    deltaX *= options.wheelDelta;
    deltaY *= options.wheelDelta;

    // initialize flags if this is the first tick
    if (!wheel) {
        data.target.data(datakey).dragging = flags.dragging = true;
        data.wheel = wheel = { timeout: null };
        toggleThumbs(thumbs, options, true);
    }

    // actually modify scroll offsets
    if (options.wheelDirection === 'multi'){
        this.scrollLeft -= deltaX;
        this.scrollTop -= deltaY;
    } else if ( options.wheelDirection === 'horizontal') {
        this.scrollLeft -= delta;
    } else {
        this.scrollTop -= delta;
    }

    if (wheel.timeout) { cancel(wheel.timeout); }

    moveThumbs(thumbs, sizing, this.scrollLeft, this.scrollTop);

    wheel.timeout = wait(function() {
        data.target.data(datakey).dragging = flags.dragging = false;
        toggleThumbs(thumbs, options, data.wheel = null);
    }, settings.thumbTimeout);

},

This code can also be found on GitHub, at https://github.com/zachflower/Overscroll.

Read more

I tend to spend a lot of my time in the command line, and as such, am constantly finding ways to avoid leaving it. My new favorite trick is to write WordPress blog posts directly in Vim. I’ve detailed the steps below:

Step 1: Install MacPorts

Creating a WordPress blog post from the command line requires a few steps, the first of which is installing MacPorts on your Mac. Installing MacPorts isn’t trivial, however the great people at MacPorts have created a good tutorial on how to get everything set up. For details on installing and configuring MacPorts, visit http://www.macports.org/install.php in your browser.

Step 2: Install python, mercurial, and asciidoc

After you have installed and configured MacPorts, the next step is to install a few dependencies. Python and AsciiDoc are both required in order to use the blogpost script we will be downloading soon. The commands to install those three tools are as follows:

Install Python

1
sudo port install python

Read more

My ~/.vimrc

0 Comments | Read more

I wanted to take a quick minute and post my config file for VIM, my favorite code editor. I’ve also included a list of my favorite VIM plugins.

* Pathogen – Manage your ‘runtimepath’ with ease.
* NerdTree – A tree explorer plugin for vim.
* delimitMate – Provides auto-completion for quotes, parens, brackets, etc.
* SuperTab – Perform all your vim insert mode completions with Tab.
* SpaceHi – Togglable syntax highlighting of tabs and trailing spaces.
* CloseTag – Functions and mappings to close open HTML/XML tags
* Command-T – Fast file navigation for VIM.
* Syntastic – Syntax checking hacks for vim
* Tagbar – Vim plugin that displays tags in a window, ordered by class, etc.
* Fugitive – A Git wrapper so awesome, it should be illegal.
* Powerline – The ultimate vim statusline utility.

Read more

I’ve always loved working in the command line. As a software developer, I spend much of my time in a terminal. Often times, I prefer to use apps that run natively in the terminal (either for the sake of fun or convenience). Here is a list of some of my favorite tools that I use in the OSX Terminal. This is by no means a comprehensive list, and may grow as time goes on.

./pianobar

./ncmpcpp

./pdsh

./ssh

Read more

I recently started developing some personal projects that require reverse geolocation using a given latitude and longitude, but when I started to look into an API, I discovered that most of the ones out there have either laughably low rate limits (2500 requests a day Google?), or costs more than I was willing to pay. So, the next logical solution, was to create my own reverse geolocation API. There are a ton of datasets out there that help you map Latitude and Longitude to real locations, some cost a ton of money, others are freely available. Because I only need locations in the United States of America, and don’t need to be 100% accurate on the determination of the nearest city, I opted to use the Free Zipcode Database from http://federalgovernmentzipcodes.us. This dataset is compiled from multiple sources, including the US Geological Survey GNIS Dataset. The Latitude and Longitude information is accurate up to less than a mile, which is plenty close for my needs. They offer two datasets: Primary Locations and All Locations. Because All Locations is useful for cities with multiple zip codes only, I opted to use the Primary Locations dataset. This gives us one record per city, which means we won’t get any duplicate latitude and longitude results.

Create Schema

After reading their spec, which is defined at the bottom of the download page, I hopped into MySQL and created a table with the following schema:

Read more

Note: This post assumes that you already have Tor installed and configured on your server. If not, visit the Tor Project Homepage for instructions on how to set it up.

I love writing web crawlers and data aggregators in PHP. They say knowledge is power, and I find it exciting to write applications that allow you to gather up as much knowledge as possible. Sometimes, though, you want to gather your data without revealing your identity to your target. This can be for both good and bad reasons, but let’s assume it is for a good reason that you need to keep hidden. The Tor Project is a great way to accomplish this task. Tor allows you to anonymously browse the web, and you can configure the applications on your computer to run through the Tor network. The script below outlines the process it takes to randomly refresh your IP address on Tor, and then run a cURL request through your local Tor proxy, providing a unique identity and anonymity every time you run the script.

For this particular example, I am sending a request to http://whatismyip.org to demonstrate the changing IP address. If you have a greater understanding of cURL, there are many more steps that can be taken to mask your identity as well, but I won’t go into that here.

PHP

Read more