Thursday, April 17, 2014

Changing Directories Faster

Having a rough time navigating around?  Try using these couple of commands to help speed you up:

Use pushd and popd (manage a stack of directories you'll revisit):
pushd /etc/
popd

Change to the previous directory you were in:
cd -

Home directory: /home/user
cd ~

Evaluate code inline to change directories:
cd /home/`whoami`

Search for a previous command that you've entered via reverse-i-search:
Use R

Also, popularly use your history up/down arrows.  

Wednesday, April 16, 2014

IntelliJ: Multiple Cursors and Selection

As a programming who's worked in IDE's such as Eclipse/IntelliJ and now works with Sublime you'll be excited to hear that IntelliJ now supports multiple selections and editting:


Woot woot!

For Mac OSX:

Multiple Cursors with mouse:
Visit Settings > Keymap > Editor Actions > Add or Remove Caret and enable ⌥⇧ + Mouse Click.  


Change Multiple Occurrences:
Press ⌃⌘G to change multiple occurrences of selection in your code.  


Friday, April 11, 2014

Writing Fast Javascript - Compiler Optimization (V8, Node.js)

Understanding how a compiler optimizes code can add significantly increase the efficiency of code.  Working within a team we've run into all kinds of styles/preferences of Javascript code.  Of course, with a language like Javascript it's important to understand that one style/preference can have penalties.
So for the last few years, Lars Bak has been getting a bit of attention for bringing speed to Javascript through the implementation of OOP compiler technology to the Javascript JIT (Just-In-Time compiler) in V8.  Bak worked on several compilers in the past and has a great deal of experience he brings from writing many VM's.

V8 has been making waves through Google's mail service, Gmail, and their suite of office apps, Google Docs.

http://www.ft.com/intl/cms/s/0/03775904-177c-11de-8c9d-0000779fd2ac.html#axzz2ybGxAlPI

Considering the idea of creating Objects dynamically:

var point1 = {
   x: 1,
   y: 2
};

And modifying them:

point1.x = 5;

It's important to note the way these optimizations work is through an assumption that dynamic languages have a inherit structure.  And the JIT in V8 takes advantage of this structure.

Writing a function such as:

function Point(x, y) { ...

Causes the JIT to create a class definition.  Assigning values within that function:

function Point(x, y) {
  this.x = x;
  this.y = y;
...

Then signals to the JIT to transition the class to a class definition with specific parameters this.x and this.y.

This allows the engine to run highly optimized.  V8 does not use the traditional technique of compiling Javascript to intermediary bytecode but instead compiles Javascript to native machine code.

Changing the structure of an object can cause it to degrade into a hash, which is tremendously slow.

I'd love to see how Dart makes headway and changes the landscape for Javascript.

Here Lars Bak talks about some optimizations in V8:

http://channel9.msdn.com/Shows/Going+Deep/Expert-to-Expert-Erik-Meijer-and-Lars-Bak-Inside-V8-A-Javascript-Virtual-Machine

Friday, January 17, 2014

Robomongo MongoDb Client

Been looking for a good MongoDb client for a while.  Robomongo by Paralect has been promising.

http://robomongo.org/


Saturday, March 02, 2013

Coordinating Nodejs Events EventAggregator

Been looking for a quick way to synchronize multiple events and callbacks. Looked around and found a few solutions but nothing exactly what I was looking for.

Henceforth, wrote up a quick module called EventAggregator.

npm install event-aggregator

So here's the problem.  There's multiple resources we're waiting for these asynchronous operations to complete.  Since we're looking to avoid nesting the code several levels deep inside of some functions, what we'll do is subscribe to several events and execute the necessary actions when they've completed.

EventAggregator allows management of several triggering events each with their own lists.  Multiple triggers can be set up by passing an array instead of a string for the triggering event.

Load the module:

var EventAggregator = require('event-aggregator').EventAggregator;

Subscribe to the events:

var aggregator = new EventAggregator(); 

// Resource 1 
aggregator.waitEvent('complete', resource1, 'ready'); 
aggregator.waitEvent('complete', resource1, 'connect'); 

// Resource 2 
resource2.createConnection(aggregator.waitCallback('complete'));

Set up a listener.

aggregator.on('complete', function() { // ... });

It's up on npm (https://npmjs.org/package/event-aggregator). It's also up on git (https://github.com/henrytseng/event-aggregator).

Thursday, August 23, 2012

Choosing To Use PHP/Kohana

There seem to be so many blog posts about using Ruby on Rails or Python/Django these days that I thought I'd voice some thoughts about how PHP/Kohana is relevant and still a strong choice.

Let's get this straight though, the languages:
  • PHP
  • Ruby
  • Python
And the frameworks I'm talking about are:
  • Kohana (PHP)
  • Ruby on Rails (Ruby)
  • Django (Python)
It can be a tremendous ear sore when people mix these up.  On the other side of the spectrum, it's also annoying to hear people rant about which languages are better than another.  It's very important to understand that the 3 of these languages can accomplish the similar goals.

If you're not familiar with Kohana you can find it here.
http://kohanaframework.org/index

Kohana is still a growing framework, but it's very strong and has a lot of potential.  There have been some ORMs such as Sprig and Jelly developed by some talented developers.  It has very fast benchmarks and good code organization through an HMVC structure.

All software is built for a purpose, the goal should always be reaching that purpose while maximizing the return and minimizing the energy expenditure.  And the value I'm talking about is not always quantifiable but there is tremendous value in building a team or growing a technology. 

The choice is clearest when cost is a very prohibitive factor.  PHP developers are in the greatest quantity out there and hosting costs for Apache-PHP-MySQL services are amongst the lowest.  In addition, while some give a notion that PHP is growing dated is still amongst the higher performers.

There is something to be said about appreciating a language because of its elegance.  When it comes down to keystrokes the fewer the better.  It's true that when we're talking about development the real work that gets accomplished is physical work.  But the greatest deal of work that gets done is the architectural work.  Designing well thought out software is 80% of the battle.  When we talk about debugging problems in software the more teammates getting involved later in the development process the most costly the issue becomes.  Practicing unit testing and regression testing properly goes a long way.  And when there is a launch making repairs post launch can require migration strategies and all kinds of headache.  While debugging in inevitable, a poorly thought out project can cost ten fold in comparison to a well built project.

I've heard that there are many unskilled PHP developers in the market.  I think it's appropriate to say that using Ruby or Python can also befall unskilled developers or even skilled developers who are poor decision makers (e.g. - tunnel or narrow visioned).  The important part of building a team and therefore executing a project when you're a team lead is to spend time with each of the resources you bring into the project.  Getting on the same page with all of your team members is always key.  As with PHP, there are skilled PHP developers who can build strong object oriented code.  Also, in the same vein, PHP is also closer to C/C++.  Most C/C++ developers tend to have stronger backgrounds.

Ruby has gained loads of ground from people hearing that it is able to build applications in months rather than years, but the real benefit is the best practices followed by its developers which can translate into other languages.

Don't get me wrong though.  Ruby and Python are great languages and I fully appreciate their respective frameworks when I work with them.  Python also has a large number of highly optimized routines.

A Comparison Between Ruby, PHP and Python from Udemy

Here's a great info graphic that compares Ruby, PHP and Python from Udemy.  It makes a good comparison of the popularity of PHP versus the execution speed of Python and highlights PHP and Python as languages you should know if you're looking for work or looking to hire.


Thursday, July 26, 2012

Tracking Application Build Versions Through Git Hooks

One thing I notice that development teams often lack is unified conventions. Most people like to do things their own way. That makes it hard to build a strong development process, but when everyone can agree on flexible, robust methods of approach we can do a whole lot to make everyone's lives on the team easier.

Tracking software version is important. It becomes even more important when you need to constantly push files to production environments or coordinate versions between developers.

Here's we're doing more and more in our development process at Canvas to coordinate multiple versions for an application we're building on Kohana PHP Framework. As an aside, Kohana is a great up and rising HMVC framework for PHP. Our team has been building on it for about a year now and we're pleased with the results.

Kohana has configuration files and we're updating application/config/version.php via a git post-commit hook.

So here's the version.php file:

<?php defined('SYSPATH') or die('No direct access allowed.');
return array(
  'version' => '1.2.8',
  'last_modified' => 'Thu, 26 Jul 2012 22:59:45 EDT',
);

As you can see the file is pretty basic. It simply stores a version and a timestamp.

Git hooks are simply scripts which get called automatically when a specific git command is made. We've set up our script as a post-commit so that each time a commit is made our script fires off.

This Git script resides here in .git/hooks/post-commit

Here's the post-commit script

#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-commit".
exec php bin/post-commit.php

As you can see its a bash script that calls a PHP script. Here's an example of a simple version of our post-commit.php script

<?php
define('SYSPATH', getcwd());

$config_path = 'application/config/version.php';
$config = include($config_path);

date_default_timezone_set('America/New_York');

function increase_minor_version($config) {
  $new_ver = '1.0.1';
  if(isset($config['version'])) {
    $old_ver = $config['version'];
    $parts = explode('.', $old_ver);
    if(isset($parts[2])) {
      $parts[2] = ((int) $parts[2]) + 1;
    }
    $new_ver = implode('.', $parts);
  }
  
  return $new_ver;
}

function store_config($version, $last_modified, $path) {
  $content  = "   $content .= "return array(\n";
  $content .= "  'version' => '".$version."',\n";
  $content .= "  'last_modified' => '".$last_modified."',\n";
  $content .= ");\n";

  $fh = fopen($path, 'w+');
  fwrite($fh, $content);
  fclose($fh);
}

store_config(increase_minor_version($config), date("D, d M Y H:i:s T"), $config_path);

We're not doing much with this script here but as with our development team we can do all sorts of automation. For example, we can fire off notifications, collate version updates for our team meetings, and/or update QA bug list databases or bootstrap our application and make CLI calls in our application (which is the real reason we're firing another PHP script).

Our teams are organized so that each team member develops in separate branches. And when we coordinate our version files are consolidated and incremented accordingly.

Monday, February 06, 2012

Spotify Apps API

Spotify recently released their developer API and we already have clients asking for small apps.

Here's their API:

They have a Javascript API that communicates with the rest of their application. It seems that a lot of neat Apps can be built to leverage existing Spotify functionality and add a little more to the environment.

The apps are built through HTML5, CSS and Javascript. We noticed that they don't support WebGL but they do seem to support Flash *unofficially.

They've got a quick tutorial you can run through that is very straight forward.

Thursday, November 17, 2011

Safari Debug Menu: Changing User Agent, Debugging JavaScript

I usually don't use Safari, but here's a great item to note if you need to use it. You can enable development tools through a preference setting. Simply open up a terminal window and execute the following:
defaults write com.apple.safari IncludeDebugMenu 1
This will enable a new menu in Safari containing controls to change the user agent, disable various functions like javascript or caching, and/or start javascript debugging.

Tuesday, October 04, 2011

XAMPP Apache Could Not Bind to Port 80

Recently, I had an issue starting up Apache. My Apache instance runs on a Windows 7 development box and also shares the box with IIS 7. Immediately I thought that it was IIS and of course that's a valid assumptions but binding IIS to port 81 did not solve the issue.

I received the following error while trying to start Apache:
D:\xampp>apache_start.bat
Diese Eingabeforderung nicht waehrend des Running beenden
Bitte erst bei einem gewollten Shutdown schliessen
Please close this command only for Shutdown
Apache 2 is starting ...
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : make_sock: could not bind to address [::]:80
(OS 10013)An attempt was made to access a socket in a way forbidden by its access permissions. : make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs

Apache konnte nicht gestartet werden
Apache could not be started
Press any key to continue . . .
D:\xampp>

Running a netstat I could see that something called SYSTEM was listening on port 80.
D:\canvas\xampp>netstat -aon | findstr :80
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4

It turns out that another service called SQL Server Reporting Services (SQLEXPRESS) was causing the conflict. Stopping the service through Component Services > Services allows you to start Apache on port 80.

*EDIT
On another machine at work a service called "Web Deployment Agent Service", part of Microsoft's WebMatrix, was also preventing Apache from binding to port 80.

Saturday, September 03, 2011

Scaling Bitmaps In Flash ActionScript 3 (AS3)

I was working on composing large Bitmaps and scaling them and noticed an optimization that might have included a bug. The images I was scaling were pixel snapping and were not smoothed. This resulted in a choppy tween.

In the past avoiding choppy image animations required setting the quality to "best". Now ActionScript allows granular control of images. In my project they were embeded as external assets and pulled from a SWF file.

[Embed(source="assets/about/gfx.jpg")]

As of Flash Player version 10.3.183.5, when scaling Bitmaps in Flash smoothing and PixelSnapping are ignored when the scale is equal to 1. In order to force smooth set the Bitmap to a scale not equal to 1.0.

For example:
var bitmap:Bitmap = new Bitmap(_bitmapData, 'never', true);
bitmap.scaleX = bitmap.scaleY = .99;

Tuesday, January 18, 2011

CakePHP Bake mysql.connect Error Running XAMPP

I ran into the following error baking with CakePHP. I was trying to create the cake schema for ACL tables.


:$ ./cake schema create DbAcl

Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /htdocs/cake/libs/cache.php on line 570

Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EST/-5.0/no DST' instead in /htdocs/cake/libs/cache.php on line 570


Welcome to CakePHP v1.3.6 Console
---------------------------------------------------------------
App : app
Path: /htdocs/app
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------

Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 552

Warning: mysql_connect(): No such file or directory in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 552

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 558

Warning: mysql_get_server_info() expects parameter 1 to be resource, boolean given in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 566

Warning: mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 671

Warning: mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 671

Warning: mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 671

Warning: mysql_real_escape_string() expects parameter 2 to be resource, boolean given in /htdocs/cake/libs/model/datasources/dbo/dbo_mysql.php on line 671


The issue that I didn't realize quick enough was that the CakePHP script wasn't using my XAMPP's PHP executable. Another instance of PHP was being run since it was located in my $PATH.

This can be easily corrected by correcting your $PATH with a quick visit to vi.

Tuesday, November 16, 2010

Taking screen captures of websites

Here's a great way to programmatically create screen captures of sites. It uses a python script to access WebKit and generate a PNG. It would be fairly easy to add some logic to make it crawl a site to show clients. We had to use this to grab some shots of a site for a routing phase of a pharmaceutical project.


There is also another program called Paparazzi! It provides a GUI and allows a little bit of interactivity for clicking through.

Saturday, September 25, 2010

Reformatting XML with TextWrangler Script

Here's a great tip for reformatting XML. I'm reposting this. I use TextWrangler and use the UNIX Script.

Use Unix Filters and create the following script to use, Reformat XML.sh:

#!/bin/sh
xmllint --c14n "$*" | XMLLINT_INDENT=$'\t' xmllint --format -

Thanks Magpie.


Thursday, September 02, 2010

Fixing Font Rendering Issues in Google Chrome for Mac OSX

While I'm writing this the Google Chrome browser is still a beta. But I still want to use it.

So the problem is that I open up Chrome and it runs into a font issue when I'm using fonts installed with my font management software (i.e. - Linotype FontExplorer X, FontAgent Pro, etc...).

I see the following characters:


The problem is that Chrome for Mac OSX is looking for font files at the following location:

/Library/Fonts/

Where these font management software programs install fonts to a different location. To remedy the problem simply change your font folder and Chrome should read the fonts fine.


On FontExplorer X 1.2.3, you can simply open up Preferences and go to the Advanced tab. Here you can change the location of font files. Yeah I run it because it's free.

Font Book which is provided by Apple on Leopard and up, seems to install for use with Chrome with out any issues. But then again, Font Book isn't exactly the best solution for font management when you have six thousand fonts.

Wednesday, September 01, 2010

How to Enable Flash Content Debugger Plugin on Google Chrome Browser for Mac OSX

This is applicable to Google Chrome 5.0.375.127 for Mac OSX.

To enable the Flash Content Debugger Plugin on Google Chrome. Simple disable the plugin distributed with Chrome. Of course, you'll also need to install the content debugger version of the plugin as well.

To disable the plugin distributed with Chrome open your Preferences and select the tab entitled "Under the Hood":

Then open Content Settings:

Now click on the link "Disable Individual Plugins":
On the plugins page both the plugin distributed with Chrome and the plugin installed from Adobe are listed. Simply disable the plugin located within the Chrome files at the location:

/Applications/Google Chrome.app/Contents/Versions/5.0.375.127/Flash Player Plugin for Chrome.plugin

On PC the distributed plugin can be disabled by opening the +Details button in the upper right and then disabling the plugin individually.

Friday, April 30, 2010

Samba write error in Mac OSX

I've been experiencing this write error for a long time.


And for the longest time I had no clue where it was occurring until I did some research and found a solution.

Here's the entry:

Basically, the solution is to turn off Unix extensions in Samba's smb.conf configuration file. Add the following to the [global] section

unix extensions = off

And restart your samba server.

Friday, January 15, 2010

Popular Programming Languages for 2010

Here's TIOBE's Programming Community index gives an indication of how popular some programming languages are becoming.

It is certainly surprising to see how fast some languages are rising up. Not to mention that Apple's Objective-C (which runs on the iPhone) is certainly up and rising at #12 and Google's Go language is right behind it at #13.

Also Adobe's Flash ActionScript is surprisingly rising the ranks now at #19.