Wednesday, June 19, 2013

Fixing localhost email on CodeIgniter under Windows

Argh. After spending a LOT of agonizing hours trying to get localhost email to work under CodeIgniter (PHP) on my Windows 7 machine, I finally figured it out. And since this is such a non-intuitive fix, hopefully I can ease the pain for someone else by sharing this.

Setup:
  • Using XAMPP + CodeIgniter
  • I had my email.php configured as very standard for localhost
    • $config['protocol']  = 'smtp';
    • $config['smtp_host'] = 'localhost';
    • $config['smtp_port'] = '25';
    • $config['smtp_timeout']='10';

Issue:
  • My PHP code kept hanging in "$this->email->send()" giving me a "waiting for localhost".
  • In my php_error_log I had "Fatal error: Maximum execution time of 300 seconds exceeded in [stuff]\system\libraries\Email.php on line 1869


Resolution:
  • Turns out that you need to specify the newlines on Windows
  • Simply update your email.php to include:
    • $config['newline'] = "\r\n";
    • $config['crlf'] = "\r\n";
  • Some additional details at the end of this thread http://ellislab.com/forums/viewthread/184596/

That's it.
Nifty

Tuesday, May 28, 2013

Fixing Carbonite UI skin issues

If you use the Carbonite online backup you may have noticed that Carbonite InfoCenter UI skin at times looks very odd. You may experience javascript errors, and see HTML code referencing Starbucks or hotels. See picture below

The good news is that this is just a caching issue, and that your backup is working as planned. However, it is really annoying to look at. It apparently can happen after you visit public WiFi networks that redirects you to a login page. Anyway, this is how to fix it.

1) Remove the folder with the cached files.
On my Windows 7 system, remove "C:\ProgramData\Carbonite\Carbonite Backup\dyncache"

2) Reload the UI
Go to the system tray
Press the left (not the right) SHIFT + CTRL key while left clicking on the green Carbonite icon. Go under "Skin" and "Reload UI"



Nifty,
Thomas

Thursday, April 4, 2013

Missing leading zeroes in XLS

If you are not careful when importing data into Excel (XLS), you often see leading zeroes be removed as XLS tries to be smart about the data it imports. However, this causes issues in Zip codes, SSNs, account numbers, etc. E.g. east coast or Puerto Rico Zip codes start with one or two leading 0s, and suddenly ZIP code 00555 turns into 555. This of course creates all sorts of fun issues in comparison, or if data is used as input into other processes, etc.

To append leading zeroes to a field, simply add a new column with the following formula, and then copy/paste the new column as values to save it. The formula works on any number of leading zeroes missing. Note that “5” in the formula below is the number of digits you expect in the correct length of the field (e.g. 5 for ZIP)

 A       B
ZIP   Fixed_ZIP
555   =RIGHT(“00000” & A2,5)

To add extra protection in case there are blank ZIP codes, simply change the formula to:
=IF(TRIM(A2)="","",RIGHT("00000"&A2,5))

FYI, the simplest way to avoid the leading zeroes being removed is to import the field as text. This is done in the "Text Import Wizard" in XLS that launches automatically when you open a text file. In step 3, simply select set the ZIP fields as text.

Nifty,
Thomas

Monday, February 25, 2013

Grep for value in a column

When doing data analysis, you often need to find records with a given value in a given column, but you want to return the whole line. The grep command will be able to do some of that but has a number of drawbacks. See older post about that at
http://niftypctricks.blogspot.com/2008/08/greping-for-column-value.html

A much simpler (and cleaner) way is to use the awk or gawk command from the command line. Note that the awk/gawk command line may look slightly different depending on whether you are on Linux, Cygwin, MKS toolkit, DOS, etc.

Assuming we have a sample tab delimited text file named in.txt:
line1 joe smith ca 4085551212
line2 joe carlson az 3334445555
line3 carl smith ny 2049998888
line4 joe smith or 5035551234
line5 mike erwin ca 4159876543
line6 mike erwin CA 4159876543

To find all records when column 5 (phone number) contained the value 555, simply use
cat in.txt | gawk -v FS='\t' 'match($5,"555")' > out.txt

The awk / gawk command "match" returns true if pattern1 ($5, meaning column 5) contains pattern2 (555), and by default that prints the whole line, so no need to explicitly put "print $0" in there. So the code sample above will return line 1, 2, and 4.

Nifty #NerdTip,
/T



Monday, February 11, 2013

Pipe to tab

Converting a pipe delimited file to a tab delimited file should be extremely simple. And many times it is if you run under a pure UNIX environment. But if you are under Windows / DOS (using Cygwin) it can be a little tricky, but there is a simple solution.

To convert a pipe delimited file, simply type:
cat FILE | tr "|" '\t' 

The trick here is that the first argument to the tr command has to use double-quotes. The standard single quotes will not work under DOS if the character you are converting is a pipe.

Nifty,
/T


Wednesday, January 30, 2013

Text editor tab in browser

This is such a cool and simple trick. Creates a simple text editor / notepad in a browser tab. This is useful for storing various kinds of temporarily data, e.g. when copy / pasting multiple items, etc.

To instantiate, simply create a new tab (in an HTML 5 compatible browser), and type in the following in the URL address bar:
data:text/html, <title>Text Editor</title><body contenteditable>

Store as a bookmark so you have easy access in the future.

Or if you want a more permanent version (uses browser's LocalStorage), type:
a5.gg

Much more details, and many "interesting" incarnations at:
https://coderwall.com/p/lhsrcq

Nifty,
Thomas