Upgrading everything to the latest version of wordpress.
Still getting used to how it works now.
Author: robert
are you a logger?
Some people are debuggers.
Stepping their way through the binary jungle, one hack at a time.
For those of you who are loggers, staring at the console for interesting events:
I had some time to write a small php script that will put a console.log for every method in a canjs controller.
Should save me loads of monotony when reverse engineering OPC ( other peoples code ).
Hope you find it useful:
<?php
if( !isset( $argv[1] ) )
$argv[1] = 'Storage.js';
$fileInfo = pathinfo( $argv[1] );
$outFile = $fileInfo['dirname'] . '/' . $fileInfo['filename'] . '_debug.' . $fileInfo['extension'];
$in = fopen($argv[1], 'r');
$out = fopen($outFile, 'w');
while( !feof( $in ) ){
$line = fgets($in);
if( preg_match('/:\W+function/', $line)){
preg_match("/\((.*)\)/", $line, $matches);
$function = explode(':', $line );
$functionName = trim($function[0]);
if( isset( $matches[1] ) && strlen($matches[1]) > 0 )
$line .= "\nconsole.log( '$fileInfo[filename]', '$functionName', $matches[1] )\n";
else
$line .= "\nconsole.log( '$fileInfo[filename]', '$functionName' )\n";
}
fputs($out, $line);
}
fclose($in);
fclose($out);
No Privacy Question for Google
Google backed up my phone’s photos and videos and went ahead and created a public album.
I guess you call this Auto Aware, well this feature is a huge violation of my privacy, and I don’t want to have this feature enabled any more.
I want my photos and videos not to be backed up. Only my contacts.
What is happening with my text messages? Is google reading them?
I bought Nike shoes and got a receipt email from Nordstrom’s and next thing I know Google+ is showing me some Nike content.
CREEPY!
You are like the stalker boyfriend of my nightmares. Can I opt out of this feature too?
Also I noticed that I have very private reviews of businesses visible on Google plus.
This is another privacy concern for me.
I don’t want everyone knowing what I have been doing all the time unless I willingly POST that information.
Please stop syphoning out content from my phone, and my other activities on other Google properties, and making them public.
Next thing you know you will be sharing my private searches with my friends, or telling them to call me cause I searched “lonely” or something like that.
I don’t need it. I don’t want it. Let me run my life, and stay out of my business.
How many god awful features are there, and how do I opt out of them?
fs-hogan == mustache.java (almost)
So lately I have been working on creating a mustache renderer in NodeJS.
My biggest challenge was finding a NodeJS module that had mustache rendering implemented closely to its Java counterpart.
I was able to find Hogan.js, the mustache renderer done by the twitter guys.
As great and powerful as Hogan.js is, initially I was a little disappointed that it was designed to run in the browser.
That meant no Filesystem operations were allowed. This is kind of like the difference between mustache.js and mu2.js. mu2.js is the NodeJS version, where partials are loaded and parsed from the filesystem, versus mustache.js, where an in memory collection of partials is used to pull from.
Well, Robert Sayer told me that I should just search NPM, and that I would find more than one “fork” of their Hogan.js.
He was right, I quickly found fs-hogan.js which did everything I needed.
The only other difference I have to note between Mustache.Java and FS-Hogan is the use of the {{.}} implicit iterator.
In the Java version, having a data model like:
{title:”some title”}
will render this template
{{#title}} <h2> {{.}} </h2> {{/title}}
without any issues into
<h2> some title </h2>
I can totally see why Sam Pullara made it work like that. Its really easy syntax to follow, and looks very elegant. Unfortunately the same thing will not render in FS-Hogan, you will get:
<h2> </h2>
To get the same result in both Mustache.Java and FS-Hogan, you must use this syntax:
{{#title}}<h2>{{title}}</h2>{{/title}}
Big shout out to Robert Sayer and Sam Pullara, thanks for all your hard work guys!
Mod_rewrite makes me feel dumb
The combination of regular expressions and voodoo just makes me want to HULK SMASH my desk into little itty bitty pieces.
I am reading this example, and right away I had a question, which the author doesn’t explain in well enough detail to make me understand.
http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/
Why in the heck do the “/user/joe/x” and “profile/joe/x” don’t match?I wish there was a way I could run a debug on this component, and watch the pattern matching tree for myself.
Because that Nettuts tutorial has comments closed, and I am just steaming at the ears at how much inane filler there is.
I always get obsessive when it comes to knowing some little detail.
MacPorts LAMP Stack
I stole this from another website:
Install MacPorts
After installing Xcode you can download and install MacPorts. The best way to install it is to use the DMG installer on the MacPorts site. On the other hand if you want to compile it from source then follow these steps:
Open up the Terminal
svn co http://svn.macports.org/repository/macports/trunk/base/ cd base ./configure make sudo make install
I recommend whichever way you install macports you should run this command to make sure everything is up to date:
sudo /opt/local/bin/port -v selfupdate
If nothing as gone wrong so far then you should have MacPorts fully setup. Only one more thing to do before installing PHP/MySQL and Apache
Update your system paths
Just so I don’t have to keep on typing /opt/local/bin all the time i’m going add that directory to my PATH. This information can be stored in your .profile which runs every time you start a new terminal. If you don’t have a .profile file use these steps to create one:
cd ~ echo 'export PATH=/opt/local/bin:/opt/local/sbin:$PATH' >> .profile
and that’s that. If you open a new terminal window (yes do that now) then those directories will be searched for terminal commands before the ones in the default path.
Setting up the LAMP stack
Enable SSL – if you want to!
Before installing PHP, i’m going to make sure that the version of curl installed is compiled with SSL enabled. If you don’t need or care about SSL then you can safely skip this step.
sudo port install curl +ssl
You should note that regardless if you run the command above first or one of the ones below then MacPorts will download a whole bunch or ports that are required to install that port or one of its dependencies. Also these commands may take sometime, so give it a while or go make a cup a tea.
Install MySQL
This one is fairly simple, well kind of…
sudo port install mysql5-server
Note: a lot of blogs recommend installing just the mysql5 port, but if you want the option to have MySQL start automatically at startup you’ll want to install the server. The mysql5-server port installs the mysql5 port anyway, so you can’t lose!
If you want to run MySQL at startup then run this command after the port finishes installing
sudo port load mysql5-server
Finally to make sure that the database if fully setup you must run this command (before starting up any mysql process!)
sudo -u _mysql mysql_install_db5
And make sure you pay attention to its instructions! Personally I didn’t do anything here as this is a development setup for me, so I prefer to keep my settings loose. Although if you want MySQL commands in your terminals path (like port) then run these commands and start a new terminal:
cd ~ echo 'export PATH=/opt/local/lib/mysql5/bin:$PATH' >> .profile
Create /opt/local/etc/mysql5/my.cnf, add the following to it and save
[mysqld_safe] socket = /tmp/mysql.sock
Also to remain compatible with other programs that may have been coded to look for the socket file in its original location then add this symbolic link:
sudo ln -s /tmp/mysql.sock /opt/local/var/run/mysql5/mysqld.sock
Install PHP & Apache
Ok we’re finally installing PHP with MySQL support and Apache (FastCGI is just being installed separately for use with some debugging and profiling tools).
sudo port install php5 +apache2 +pear +fastcgi php5-mysql +mysqlnd
Like MySQL if you want Apache to start automatically when you start your computer then run this command after the port installs (as shown while the ports are installing)
sudo port load apache2
Configure PHP
To customize php, copy /opt/local/etc/php5/php.ini-development (if this is a development server) or /opt/local/etc/php5/php.ini-production (if this is a production server) to /opt/local/etc/php5/php.ini and then make changes (see below).
i.e. for development:
cd /opt/local/etc/php5/ sudo cp php.ini-development php.ini
i.e. for production:
cd /opt/local/etc/php5/ sudo cp php.ini-production php.ini
To customize php edit (using your favourite editor) /opt/local/etc/php5/php.ini to configure it properly, make sure you set the correct timezone (for myself it’s this):
date.timezone = Europe/London
Configure Apache
If this is your first install, you need to activate PHP in your web server.To enable PHP in Apache, run
cd /opt/local/apache2/modules sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
Open /opt/local/apache2/conf/httpd.conf in your favourite text editor (it’s vi for me, but feel free to use pico, emacs or whatever!).
sudo vi /opt/local/apache2/conf/httpd.conf
If you want to change the default MacPorts Apache document root to match default Apple’s Apache (personally I didn’t, but I found this information on another blog – so it might be useful to some), change:
DocumentRoot "/opt/local/apache2/htdocs"
to:
DocumentRoot "/Library/WebServer/Documents"
If you changed the DocumentRoot, change the Directory directive from:
<Directory "/opt/local/apache2/htdocs">
to
<Directory "/Library/WebServer/Documents">
For PHP to work correctly you must add index.php to the dir_module directive:
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
Add a new mimetype so that Apache will direct files ending in .php to the PHP module for processing. Add the following within the <IfModule mime_module> block. Without this, all you’ll see is the text of your PHP scripts
AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
And finally, to enable user directories, uncomment:
Include conf/extra/httpd-userdir.conf
But if you are going to use virtual hosts (as described below) then uncomment this line in addition to (or instead of) the line above:
Include conf/extra/httpd-vhosts.conf
Save and close the httpd.conf file.
Advanced Post-Configuration
Configure Apache Virtual Hosts
Now unless you just want to access your new web server using http://localhost you might want to set up some virtual hosts for Apache. I personally only need one virtual host atm i.e. http://testing.example.com. Virtual hosts need to be configured in two places, the hosts file (/etc/hosts) and the Apache virtual hosts file (/opt/local/apache2/conf/extra/httpd-vhosts.conf).
Firstly add this line to /etc/hosts after the localhost has been defined i.e.
127.0.0.1 localhost 127.0.0.1 testing.example.com
Then you must edit the virtual hosts file /opt/local/apache2/conf/extra/httpd-vhosts.conf and add this configuration
<VirtualHost *:80> ServerAdmin webmaster@testing.example.com DocumentRoot "/opt/local/apache2/vhosts/testing.example.com" ServerName testing.example.com ServerAlias www.testing.example.com ErrorLog "logs/testing.example.com-error_log" CustomLog "logs/testing.example.com-access_log" common </VirtualHost>
The document root can be anything you want as long as apache has permissions to read that directory i.e. in this case you can:
sudo mkdir -p /opt/local/apache2/vhosts/testing.example.com cd /opt/local/apache2/vhosts/ sudo chmod -R 755 testing.example.com
You can do this process for as many virtual hosts as you want. Also I personally keep all my websites stored in my user directory – yes bad on a server, but this is my personal development machine. Finally don’t forget to comment out or remove the example vhosts from http-vhost.conf or you’ll get warnings while starting up Apache, they are harmless to leave in, but it’s probably for the best to remove any potential errors
Installing extra PHP modules
There are plenty of extra PHP modules available from MacPorts, you can get a list of them by using this command. Although you won’t need any of the MySQL ones as you’ve already compiled it into PHP.
port search php5-
Here is the list of PHP5 ports I installed
sudo port install php5-openssl php5-curl php5-gd php5-iconv php5-http php5-mcrypt php5-xdebug
Updating MacPorts
MacPorts is simple to update, every few weeks I just run the command below to check for any outdated ports (i’ll also update this post with any changes to this process I discover)
sudo port outdated
to update all installed ports to the latests and greatest
sudo port upgrade outdated
That’s It
Now if you restart your computer and add code into the document root of your website (in this case http://testing.example.com) then you should have a fully working web server with PHP and MySQL. Ok it wasn’t easy, but for me it’s the best solution over the longer term
iTerm2 keyboard shortcut for end of line and beginning of line
So its not that easy to switch to a brand new computing platform and interface at age 31.
Previously I used my Microsoft Elite keyboard as a shield between me and the MacBook Pro.
Today I Learned: The function key and arrows serve to replace the HOME, and END keys. 🙂
Also I was able to configure my iTerm2 to easily get me to the beginning and end of line.
I’m still new at this, and mapping Alt+Left Arrow and Alt+Right Arrow didn’t seem to work at first.
So I mapped Ctrl A and Ctrl Z to go the beginning and end of line.
Simply open the preferences, hit the key tab, and the plus sign to add your own mapping.
Then hit the keys you want mapped, and from the drop down select “Send Escape Sequence”
[H gets you the beginning, and [F gets you to the end 🙂
Screen Shot attached.
CanJS is really the new hot thing in JavaScript
So its official.
I was at a Hare Krishna Temple in Silicon Valley. And while I was relaxing a bit, I overheard another pair of engineerings talking.
I couldn’t help but eavesdrop.
To my surprise, they were talking about CanJS. One of the engineers was RAVING about it to the other one. Finally I had to inject myself into the conversation and inquire as to where they worked.
And again to my surprise, they didn’t work at a large company, but a startup.
Bitovi is a name I am hearing more and more while I am up here in Silicon Valley!
Why? The simple answer, it makes things easier. You just have to write way less code. About 20% less.
It also organizes your code into better more logical, and therefore readable, structure.
So yes, thank you Brian Moschel, for JavaScriptMVC and for CanJS.
They are the IT thing in I.T. this year of our lord, 2013.
PhantomJS + Jasmine vs Selenium Web Driver
Recently I started using phantomjs, which is a headless browser based on web-kit, for automated JavaScript testing.
Now when I was playing around with Selenium @ ABC Family, I really liked how the web driver started a browser instance and executed the test suite within it. This means Selenium is actually a better, or closer match, in terms of automated testing, because the browser is not headless. Although I don’t know all the internals of Selenium, that was my first impression.
But the positive thing about using the grunt, jasmine, phatomjs combo to run unit tests, is that we can start a jasmine server, which lets you check your code in many other browsers. That means you are not limited by the Selenium browser library of supported browsers. You can actually pick up your phone, or tablet, and point the browser to the test server, and see how your code executes on that particular system ( Device, OS, Browser). True this is not something that can be used with 100% automation on its own, but it does give you the freedom to experiment and see the behavior of code in a large variant of systems. This means that with services like DeviceAnywhere, you maybe able to cover and automate the testing of all kinds of strange fringe devices.
Something else that is interesting is that in Selenium, you can’t really hook, or spyOn member methods. While a lot of the tests written in jasmine, can be executed similarly with Selenium, because they just check for a class that has been added or removed from a DOM element, jasmine provides more integration with the code base.
The classes are loaded, along with a html fixture, and then executed. This is how the server works, by creating a #sandbox div where it loads the html fixtures for each test, loading the javascript into the page, instantiating the class, and then begins execution of the test suite. Now the opposite argument is, again, this is not how the site would be like in the wild. Other components would live on the page. So Selenium gives a more accurate assessment of how the code actually works on the end user’s system, since it loads the entire site, via a client side browser.
Now as a Computer Scientist, Java vs JavaScript argument is mute to me when it comes to choosing a “platform”. Because ultimately its like comparing apples to oranges, when you really look at the language structure and what they are designed to accomplish. Two different tools for different jobs. As a front end developer, who wants everything to be easy, there is definitely a benefit to having a unified language for creating build tools, server side applications, and user interfaces. So at some shops, where ROI is important, it’s a good idea to keep the tools all in the skill set of the human resources currently on staff. For UI people, this means JavaScript > Java. This is a good argument for using tools like grunt, and phantomjs, and jasmine, since they are all JavaScript based, they empower the new kingmakers (Open Source Developers).
Which is actually still not a big argument against Selenium Web Driver, because Java is very easy to install, you are not going to be making many changes to the driver itself, and the interface for running the Selenium Web Driver could potentially still be written in JavaScript.
Therefore the argument could be made that Selenium and Jasmine don’t have to be mutually exclusive, while it would bloat the build time to include both systems, a separate box, and process, could be used, to test with both, or the one that is missing in the build process.
While its too soon for me to say, “Dude, Selenium is old news.” I can say that all this merits more experimentation and testing. A very exciting time for Computer Scientists indeed. So much Brain Candy!
Real Web Developers don’t do “Builds”
I don’t want to wait for some MAVEN command to execute.
I just want to refresh the browser!
So this is where Charles Proxy comes to the rescue!
The “Map to Local” feature allows you to quickly map your resources to a live implementation on a production, or development environment.
Really great feature, that saves a lot of time. Even the uploading to a generic hosting step can be skipped when doing changes to static resources. So this tool is good for Enterprises and SMBs.
Usually I would completely avoid extraneous non open source solutions. The KISS principle is something I apply not just to my coding, but to my workflow as well. Unfortunately, I don’t always get to decide what platform and workflow structure I have to interact with. And this where tools like Fiddler and Charles become indispensable in preserving my sanity.
While on the Mac environment, I am currently using Charles Proxy, Fiddler2 also provides this feature, hidden in the AutoResponder tab. Simply activate “Map URLs to local files”. And Fiddler should be able to run on Linux / Mac, although I haven’t tried it yet.
Check it out http://www.fiddler2.com/fiddler/help/video/default.asp