Wednesday, July 27, 2016

ColdFusion to Node.js Conversion 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):
127.0.0.1       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" https://wiki.bitnami.com/Components/Apache/htaccess_configuration.
In this instance I have an EC2 instance spun up from a BitNami (HVM) AMI.
The default file to edit is

/opt/bitnami/apps/wordpress/conf/htaccess.conf
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/.*" http://www.yourdomain.com/
</Directory>
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/ctlscript.sh 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/127.0.0.1. 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 "127.0.0.1" AND CGI.HTTP_USER_AGENT EQ "CFSCHEDULE">
        <!--- let the CF ScheduledTask pass through --->
        <!--- add custom logic to impersonate authenticated user --->
    <cfelse>
        <cfset filters(through="getCurrentUser,isAuthenticated,isAdmin", type="before")>
    </cfif>
</cffunction>

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

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

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.

<cfscript>
//path to image
imagePath = "pathToImage";

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

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

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

//pass in FileSeekableStream
pb.add(fss);

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

//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
fss.close();
</cfscript>

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 com.apple.finder AppleShowAllFiles -bool true
To hide hidden files again in Finder, run this command in Terminal
defaults write com.apple.finder 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

Wednesday, May 11, 2011

Fixing DNS issue on MacBook Pro

This may be an issue with 10.6(Snow Leopard) altogether or just with the MacBook Pros, but every once in a while the internal DNS settings get hung up or crap out or just stop working!

You're connected to the internet, you've checked the connections, you've got on other devices , you've asked co-workers if they are having issues with the internet, you've pulled your hair out, banged your head against the wall, you get my drift.

Whatever you do or try your $2000 MacBook Pro will not do one simple thing CONNECT TO THE INTERNET!!

Hopefully this solution will work for some of you and save the hair on your head.
Run these commands from terminal(copy command from sudo to plist):

sudo launchctl unload /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

THEN

sudo launchctl load /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

and bingo bango everything is just peachy again!

Wednesday, April 20, 2011

CFBuilder 2 Tour comes to Nashville this week!

WHEN: Thursday, April 21st, 2011 at 6:00pm CDT

WHERE: Russ Carroll Financial Peace Conference Center,1749 Mallory Lane, Brentwood, Tennessee 37027
Map of Location

SPEAKER: Greg Wilson - Adobe evangelist for AIR, ColdFusion, Flex and LiveCycle ES

WHAT: Greg Wilson from Adobe will be here to talk about CFBuilder 2, ColdFusion, and even some Flex on mobile stuff, including Flex on iPad/iPhone! We are SUPER excited to have the opportunity to get the surrounding ColdFusion and Flex communities together for this event. Greg Wilson is an AIR, ColdFusion, Flex, and LiveCycle ES evangelist at Adobe, and many of you may remember him from the ColdFusion 9 tour a couple of years ago.

HOW: Register at the Nashville ColdFusion User Group site.
RSVP for this meeting ...