Clean Up Google Drive Icon Files

I had a Git repo that I was storing on Google Drive (Yes that probably was not a great idea, but it was a lazy way of sharing some pdfs in the repo with a non-technical coworker). The Google Drive app on the Mac uses an “Icon” file to indicate sync statuses of folders.  Unfortunately this kept screwing up the repo by also putting “Icon” files in all the folders in the .git directory.  Having the repo was more important than it being in Google Drive so I moved the folder out of Google Drive.  Once the folder was moved the “Icon” files remained and the repo was still throwing an error when I tried to code in Adobe Brackets.

Here is how I cleaned up all the Google Drive “Icon” files.

WARNING: BE SURE YOU DON’T HAVE FILES NAMED WITH “Icon” AS THE FIRST 4 LETTERS OR THIS WILL DELETE THEM.

  1. Open terminal
  2. Change directories into the folder that was once in Google Drive
  3. Issue the following terminal command:
    find . -name 'Icon*' -type f -delete

Now the repo is back to normal.

SQL Server SELECT into existing table

This morning I needed to add a single record to an existing table in database1 from an existing table in database2. Here’s how I was able to do it:

INSERT INTO database1.dbo.tablename
     SELECT *  
     FROM 
          database2.dbo.tablename
     WHERE 
          ID='4d08aeb0bedd01452dfef3eabc2816dcc75533c8'

Please note that the databases use a SHA-1 Hash for the ID field. If you use an IDENTITY field in SQL you’d have to take some extra steps to briefly allow inserting an IDENTITY field.

Using a ColdFusion Ternary Operator for an Optional Tag Attribute

Today I had to write a script to process a form and send an email as part of the processing. The form allows the user to specify an email address to bcc, but it’s not required. I’m a big fan of using the Ternary Operator for doing either/or stuff like css classes. So I decided to extend that fandom to set the bcc attribute of the <cfmail> tag if the email specified in the form was valid.

Assumptions for this example:

1. You have validated form.bccEmail as a valid email.
2. You have a default mail server specified in Application.cfc or CFADMIN.
3. You may see more utility in using the Ternary Operator for other conditional cases.

The “magic” is in the bcc attribute below:

    
	    Message Body here...
    

ColdFusion function returns space before value

I had an annoying issue this morning where a function I wrote that rounds and formats values for use in an internal financial app kept sticking a single space before the value returned. This was obviously not good for a financial app. After spending 10-15 minutes tearing the function’s innards apart it turns out what was going on in the function was not the cause. The cause was simple.

In a tag based ColdFusion function you need to be sure to include the ‘output=”no”‘ attribute.

 
     ... MAGIC STUFF HERE ...

A LESS Mixin to change font-color based on font-size

Just a little LESS fun for the day… Here is a LESS Mixin to change font-color based on font-size.

Green big.
Yellow just right.
Red little.

It can be used with or without passing units (without units will use pixels). Adds bold just for fun.


.colorBySize(@pxValue) when (@pxValue < 12px){ color:red; } .colorBySize(@pxValue) when (@pxValue =< 16px) and (@pxValue >= 12px){
color:yellow;
}

.colorBySize(@pxValue) when (@pxValue > 16px){
color:green;
}

.colorBySize(@_) when not (ispixels(@_)){
font-size: ~"@{_}px";
// font-size: @_;
font-weight: bold;
}

.colorBySize(@_) when (ispixels(@_)){
font-size: @_;
font-weight: bold;
}

p.little{
.colorBySize(9);
}

p.justright{
.colorBySize(12);
}

p.big{
.colorBySize(18);
}

Copy files from one Windows server to another and retain permissions

Just want the script?

If you don’t want to read the blah blah blah you can access robocopy-script on Github

I want to know the details…

At my day job I was tasked with migrating several websites and folders from one Windows server to another. The sites have a ton of quirky permissions settings because they are mostly intranet sites. Several have anonymous browsing turned off. As you may or may not know if you just copy them via drag and drop in File Explorer you will lose all of those permissions that took years to refine. Additionally you will lose creation dates, etc.

After some research I determined that Robocopy was what I needed to retain all that valuable cruft information. Unfortunately (or fortunately if you dig command line stuff) Robocopy is a command line tool with quite a few flags. A little more digging revealed there is a GUI for Robocopy which allows you to save scripts, but I decided to roll my own script.

Features:

  • A simple “config” section in the script where you define the to/from locations
  • A config option to run attended or unattended (set this in the script)
  • Logging
  • Utilization of the following flags (descriptions are verbatim from the Robocopy documentation):
    • /E – Copies all subdirectories (including empty ones).
    • /SEC – Copies NTFS security information. (Source and destination volumes must both be NTFS). Equivalent to /COPY:DATS.
    • /COPY:DATSO – Copies the file information specified by copyflags, which can be any combination of the following : D – file Data. | A – file Attributes | T – file Timestamps. | S – file Security (NTFS ACLs). | O – file Ownership information.
    • /V – Produces verbose output (including skipped files).
    • /TEE – Displays output in the console window, in addition to directing it to the log file specified by /LOG or /LOG+.
    • /NP – Turns off copy progress indicator (% copied). **
    • /LOG – Redirects output to the specified file, overwriting the file if it already exists.
    • /B – Copies files in Backup mode (Backup copies are not restartable, but can copy some files that restartable mode cannot). ***
    • /R:10 – Specifies the number of retries on failed copies. (The default is 1 million.)
    • /W:30 – Specifies the wait time between retries. (The default is 30 seconds.)

** I liked seeing the progress as it copied, but all those percentages get written to the log file same as the screen.
*** Consider /Z to use restartable mode.

Obviously you could tweak the flags in the script to get a combination more suitable for you.

If this sounds like something you might find useful you can access robocopy-script on Github. I should note that this is my first public repo on Github. Yay.

Helpful Commands for ColdFusion 10 on OSX… aka Start and Stop CF10 from the command line

This post assumes you are working with the default instance (cfsusion) and that you installed ColdFusion 10 to the default location on you Mac.

STATUS:
/Applications/ColdFusion10/cfusion/bin/coldfusion status

START:
/Applications/ColdFusion10/cfusion/bin/cf-standalone-startup
OR
/Applications/ColdFusion10/cfusion/bin/coldfusion start

STOP:
/Applications/ColdFusion10/cfusion/bin/coldfusion stop

RESTART:
/Applications/ColdFusion10/cfusion/bin/coldfusion restart

Launch GUI for configuring Web Connectors:
sudo /Applications/ColdFusion10/cfusion/runtime/bin/wsconfig

RESET CFADMIN PASSWORD:
/Applications/ColdFusion10/cfusion/bin/passwordreset.sh
(Then Enter 1 for changing Admin Password and put in your new super strong password!)

.

Using not() in jQuery to exclude a member of a class

This is just a quick tip I thought I throw out there. We have an application that applies a fade to a .alert class on all its pages. We have 2 pages that need to not fade one particular alert. Here is one way it can be handled.

  1. Add a class of .notfade to the alert that needs to stay put and not fade out:
    <div class="alert alert-info nofade"></div>
  2. Place the following in $().ready(): $(".alert").not(".notfade")fadeOut(7000);

RDS Query Viewer not working: How to fix the ColdFusion Builder error: ‘/YOURPROJECTFOLDER/.rdsTempFiles/RDS Query Viewer’ does not exist

I have had this issue for a while and it finally made me crazy enough to try to figure it out. It appears that this error occurs when the “RDS Query Viewer” file does not exist in the .rdsTempFiles folder within your project.

On Mac

  1. Open Terminal
  2. Navigate to the directory where your project is located. For example type: cd /Applications/ColdFusion9/wwwroot/YOURPROJECTFOLDER and hit <enter>
  3. If the “.rdsTempFiles” directory does not exist type: mkdir .rdsTempFiles and hit <enter>
  4. If the “RDS Query Viewer” file does not exist type: touch “.rdsTempFiles/RDS Query Viewer” and hit <enter>. BE SURE TO SURROUND THE COMMAND WITH THE DOUBLE QUOTES BECAUSE THE FILE NAME HAS SPACES.
  5. Refresh the “RDS Query Viewer” view. RDS Query View should work now.

On Windows

  1. Open DOS
  2. Navigate to the directory where your project is located. For example type: cd C:\ColdFusion9\wwwroot\YOURPROJECTFOLDER and hit <enter>
  3. If the “.rdsTempFiles” directory does not exist type: mkdir .rdsTempFiles\rdsTempFiles and hit <enter>
  4. If the “RDS Query Viewer” file does not exist type: fsutil file createnew “RDS Query Viewer” 0 and hit <enter>. BE SURE TO SURROUND THE COMMAND WITH THE DOUBLE QUOTES BECAUSE THE FILE NAME HAS SPACES.
  5. Refresh the “RDS Query Viewer” view. RDS Query View should work now.

ColdFusion 9 SELECT IN query using ormExecuteQuery()

For some reason this took me some effort to figure out. Maybe others will find it useful.


CategoryList = '1,2,3';
Categories = ormExecuteQuery("from Category where Id IN (:IdList)",{IdList=ListToArray(CategoryList)});

If you know a better way please drop me a comment. I posted this in the Adobe Coldfusion forum for a few days but didn’t get anything.