Friday, February 23, 2018

Replacing your HDD with a SSD in a Mid-2009 Mac

What you'll need:
  • T6 screwdriver
  • PH000 philips screwdriver
  • SATA to USB connector ( or SATA to Thunderbolt if you feel like spending the cash)
  • Apples DiskUtility Application
  • 2.5 inch SATA SSD (e.g. Samsung 850 EVO), size is up to you
Before we swap the drives out we want to test our speeds so that we can compare with what we get afterwards. You can run the below commands a few times, then take an average if you want a better representation.

Write Speed (16GB file, lower the values of the bs and count params for a smaller file)
52.872 MB/sec write speed

Read Speed
50.6726 MB/sec read speed

Also, in the Disk tab of the ActivityMonitor you can see a real-time measurement of reads/writes per second, which where an approximate match to the values I got above.

Hook up the new drive

The next thing to do is clone the current disk over to the SDD. I used a SATA to USB connector I found online to connect it to the Mac and I used the DiskUtility app to clone the disk.
Once you plug the disk into the USB port you should get a pop-up message that says "The disk you inserted was not readable by this computer."
Options are Initialize..., Ignore or Eject.

I chose Initialize, which will automatically open the DiskUtility application. At this point you should see an orange icon with the size, brand and model of your SSD. In my case it showed "250.06 GB Samsung SSD 850 EVO 250G Media".
The disk I am replacing is showing as "250.06 Hitachi HTS545025B9SA02 Media".

Format the new drive

Next up is formatting the new drive. To do this select the new drive, select the Erase tab, select "Mac OS Extended (Journaled)" for the format and give the new partition a name. I named mine "Macintosh SSD". Double check that you have the correct drive selected, then click the Erase button, you'll get a confirmation box.

Clone the old drive

Next, we will use the Restore function to essentially clone the original drive.
Choose the Restore tab, drag and drop the original disk partition into the Source field, then drag and drop the new disk partition (that was created by the format) into the Destination field. Then click the Restore button. Be careful with this part because clicking on one of the drives without dragging it will cause either the Source or Destination fields to change.
If you get a pop-up saying "The startup disk can’t be used as a restore source." then you will have to do this from the recovery console.
To get into recovery mode follow the instructions here or hold down Command+R immediately after restarting your Mac and continue to hold it until you get the utilities window.
Once you're in, repeat the drag-n-drop steps above. It took about 2 hours for the cloning process to complete. After the cloning process is complete, click on the apple icon and choose Shut Down.

Swap out the drives

Now you can flip the laptop over, take out the screws to the cover, unscrew the two screws in the bracket holding the drive in place, gently lift the drive up just enough to pull the SATA connector off of the old drive (don't handle the ribbon, just the connector), take out the 4 screws on the old hard drive (you'll need the T6 for this part). Installation of the new drive is the reverse of the steps above.

Test results after the swap:
196.577 MB/sec write speed
272.187 MB/sec read speed

What do I do with the old drive?
I used the same SATA to USB connector that I used for the SSD to hook up my old drive.
Start up disk utility , select the old drive, go to the Erase tab,  select Security Options, slide the slider all the way to the right to the most secure option, then select Erase. This will take a while, but the 7 pass erase will ensure that nothing can be recovered. Then take the hard drive to your trusty computer part disposal company where they will also take steps to securely destroy the drive by either shredding it completely or drilling holes in the drive.

Wednesday, October 11, 2017

ColdFusion to Sails.js Conversion : Find/Replace Tips/Tricks

Use your IDE of choice, I prefer Sublime Text because it uses the Perl Compatible Regular Expressions (PCRE) engine from the Boost library and I love me some regex. I will show examples for .js syntax, but if you need this in .ejs format just add <% to the beginning and %> to the end like in the first example below.  I always have the case sensitive button off in Sublime, so if you are using a different editor make sure you use the proper ignore case flag or you may get mixed results. These examples are meant to speed up the conversion, some additional refactoring may also be necessary.

more to come...

Wednesday, July 27, 2016

ColdFusion to Node.js Conversion : Setup Part 1

This multi-part post will be community comment driven, which basically means that in an effort to not spend too much time on details that might not matter to the viewers out there, I am only going to share the details which I think are important at the time of publishing the posts. If people (or bots) comment and want more details, I will add them to the original post. As always, constructive criticism is always welcome.

Since I am currently using the CFWheels framework (which is inspired by Ruby on Rails or RoR), I chose to try out the Sails.js framework for Node.js (which is also similar to Rails).

1st thing I did was get Node and Apache working together by adding this to my Apache vhost(VirtualHost) block:
ProxyRequests on
ProxyPass / http://localhost:8124/
And adding this to my hosts file (/etc/hosts):       mynewapp.node www.mynewapp.node

This allows me to setup an alias in my host file and reference the URL as you normally would without adding the portnumber on the end of the URL. Instead of having to use http://localhost:8124/ , I can now use http://mynewapp.node
After that I installed the "sails-mysql" npm package in order to get the app working with my existing MySQL database.
npm install sails-mysql --save

The next thing I did, because one very frustrating thing you will find is that you have to "lower" then "re-lift" your sails app after every change you make. I installed sails-hook-autoreload to take care of this for me as I make code changes.
npm install sails-hook-autoreload --save-dev
// I used "--save-dev" instead of "--save" above because this package 
is not required in a production setting.
NOTE: create a "[your-sails-app]/config/autoreload.js" file with at least the following configuration:
module.exports.autoreload = {
  active: true,
  overrideMigrateSetting: false
Otherwise the overrideMigrateSetting will be defaulted to true and sets the "module.exports.models.migrate" setting to "alter" which will wipe out any database tables you have setup models for!! This is a good time to mention taking frequent backups of your database. Since I am using an existing MySQL database I am using the "module.exports.models.migrate = safe" setting for both development and production environments.

to be continued....

Tuesday, June 14, 2016

Bitnami WordPress htaccess Redirect for Author Pages

As their page notes, for security purposes, the htaccess configuration has been moved outside of the webroot and AllowOverride is set to "None"
In this instance I have an EC2 instance spun up from a BitNami (HVM) AMI.
The default file to edit is

Make a backup of the file before you edit.
Add this block anywhere in the file to redirect all author landing pages to the home page.

<Directory /opt/bitnami/apps/wordpress/htdocs/>
    RedirectMatch 301 "^/author/.*"
Customize to your liking if you would rather redirect to a different page.
When you're done editing, run this to restart apache, then test your changes.

sudo /opt/bitnami/ restart apache
/* Joey */

Sunday, November 8, 2015

CfWheels and Controller Init Caching Gotcha

I recently discovered an issue where logic inside of a controllers init gets cached when your environment is set to production. By default, when in the production environment the cfwheels setting of cacheControllerInitialization defaults to true.
At the time I had logic in the init method that checks if the user agent is CFSCHEDULER and the remote address is localhost/ I used this logic to authenticate scheduled tasks that run on a secure section of the site.
I found this when sporadically the authentication would pass even though the logic returned false and I noticed the init method was _never_ being called, which led me to find that caching setting.
The fix was to extract the logic out into another method and add that to the list of filters.

/************** Before **************/
<cffunction name="init">
    <cfif CGI.remote_addr EQ "" AND CGI.HTTP_USER_AGENT EQ "CFSCHEDULE">
        <!--- let the CF ScheduledTask pass through --->
        <!--- add custom logic to impersonate authenticated user --->
        <cfset filters(through="getCurrentUser,isAuthenticated,isAdmin", type="before")>

/************** After  **************/
<cffunction name="init">
    <cfset filters(through="isScheduledTask,getCurrentUser,isAuthenticated,isAdmin", 

<cffunction name="isScheduledTask">
    <cfif CGI.remote_addr EQ "" AND CGI.HTTP_USER_AGENT EQ "CFSCHEDULE">
        <!--- let the CF ScheduledTask pass through --->
        <!--- add custom logic to impersonate authenticated user --->

Wednesday, February 20, 2013

ColdFusion Invalid Image Format Solution

For those who have gotten the following error:
"java.awt.color.CMMException: Invalid image format" and tried
the solutions posted here with no avail.

We are going to use the power of Java's JAI (Java Advanced Imaging) library to tackle this one.

//path to image
imagePath = "pathToImage";

//create java file object, passing in path to image
imageFile = createObject("java","").init(imagePath);

//create a FileSeekableStream, passing in the image file we created
fss = createObject("java","").init(imageFile);

//create ParameterBlock object and initialize it (call constructor)
pb = createObject("java","java.awt.image.renderable.ParameterBlock").init();

//pass in FileSeekableStream

//create JAI object that will ultimately do the magic we need
JAI = createObject("java","");

//use the JAI object to create a buffered jpeg image using the parameter block we just created
buffImage = JAI.create("jpeg", pb).getAsBufferedImage();

//pass the buffered image to the ColdFusion imagenew() method.
New_Image = imagenew(buffImage);

//make sure we close the stream, or you'll pay for it later

From what I could find CF/Java chokes on some jpeg's due to their format.
Specifically speaking, the EXIF format vs. the JFIF format.
Read this for more information on these two standards.

Some cameras only add the EXIF segment to the file header of the jpeg and images from those cameras are the ones I see issues with.
To see some samples of this, check out the images on this website.
Download some of those images and see if your image processing code can handle them!

To get more information on your images check out this page and it will tell you all about it, including if the image has JFIF or EXIF segments added.

If anyone has questions about the above code, please don't hesitate to ask.

Hope this helps some of you, since I could not find any solution out there.

Friday, November 16, 2012

Show hidden files on Mac

To make hidden files visible in Finder, run this command in Terminal
defaults write AppleShowAllFiles -bool true
To hide hidden files again in Finder, run this command in Terminal
defaults write AppleShowAllFiles -bool false
Run this command to restart Finder, so that either one of the above commands will take effect ( Don't worry, Finder should restart with all of your previous windows open again )
killall Finder

Replacing your HDD with a SSD in a Mid-2009 Mac

What you'll need: T6 screwdriver PH000 philips screwdriver SATA to USB connector ( or SATA to Thunderbolt if you feel like spending ...