Friday, December 28, 2012

Py2exe Issues

When getting the directory of the file you're executing in python use the correct example:

CORRECT: os.path.abspath(os.path.dirname(sys.argv[0]))
INCORRECT: os.path.dirname(inspect.getsourcefile( lambda:None ))

If you're using py2exe, the incorrect example will just give error messages.

Thursday, December 27, 2012

Outlook 2010 - Run a Script (Blank)

Apparently a script does not equal a macro in outlook. When you're setting up a rule, you have the option to run a script. However, your macro will not show up in the script menu unless it has (MyMail As MailItem) as an argument. Example:

Sub Save(MyMail As MailItem)

SaveEmailAttachmentsToFolder "AgentReports", "html", "C:\Users\EBRNPAL\Documents\Agent Reports\Saved"

End Sub

Friday, December 21, 2012

Save Outlook Attachments Automatically With A Macro


Sub Test()
'Arg 1 = Folder name in your Inbox
'Arg 2 = File extension, "" is every file
'Arg 3 = Save folder, "C:\Users\Ron\test" or ""
'If you use "" it will create a date/time stamped
'folder for you in the "My Documents" folder.
'Note: If you use this "C:\Users\Ron\test" the folder must exist

    SaveEmailAttachmentsToFolder "AgentReports", "html", "C:\Users\Paul\Documents\Agent Reports\Saved"

End Sub

Sub SaveEmailAttachmentsToFolder(OutlookFolderInInbox As String, _
                                 ExtString As String, DestFolder As String)
    Dim ns As NameSpace
    Dim Inbox As MAPIFolder
    Dim SubFolder As MAPIFolder
    Dim Item As Object
    Dim Atmt As Attachment
    Dim FileName As String
    Dim MyDocPath As String
    Dim I As Integer
    Dim wsh As Object
    Dim fs As Object

    On Error GoTo ThisMacro_err

    Set ns = GetNamespace("MAPI")
    Set Inbox = ns.GetDefaultFolder(olFolderInbox)
    Set SubFolder = Inbox.Folders(OutlookFolderInInbox)

    I = 0
    ' Check subfolder for messages and exit of none found
    If SubFolder.Items.Count = 0 Then
        MsgBox "There are no messages in this folder : " & OutlookFolderInInbox, _
               vbInformation, "Nothing Found"
        Set SubFolder = Nothing
        Set Inbox = Nothing
        Set ns = Nothing
        Exit Sub
    End If

    'Create DestFolder if DestFolder = ""
    If DestFolder = "" Then
        Set wsh = CreateObject("WScript.Shell")
        Set fs = CreateObject("Scripting.FileSystemObject")
        MyDocPath = wsh.SpecialFolders.Item("mydocuments")
        DestFolder = MyDocPath & "\" & Format(Now, "dd-mmm-yyyy hh-mm-ss")
        If Not fs.FolderExists(DestFolder) Then
            fs.CreateFolder DestFolder
        End If
    End If

    If Right(DestFolder, 1) <> "\" Then
        DestFolder = DestFolder & "\"
    End If

    ' Check each message for attachments and extensions
    For Each Item In SubFolder.Items
        For Each Atmt In Item.Attachments
            If LCase(Right(Atmt.FileName, Len(ExtString))) = LCase(ExtString) Then
                FileName = DestFolder & Item.SenderName & " " & Atmt.FileName
                Atmt.SaveAsFile FileName
                I = I + 1
            End If
        Next Atmt
    Next Item

    ' Show this message when Finished
    If I > 0 Then
        MsgBox "You can find the files here : " _
             & DestFolder, vbInformation, "Finished!"
        MsgBox "No attached files in your mail.", vbInformation, "Finished!"
    End If

    ' Clear memory
    Set SubFolder = Nothing
    Set Inbox = Nothing
    Set ns = Nothing
    Set fs = Nothing
    Set wsh = Nothing
    Exit Sub

    ' Error information
    MsgBox "An unexpected error has occurred." _
         & vbCrLf & "Please note and report the following information." _
         & vbCrLf & "Macro Name: SaveEmailAttachmentsToFolder" _
         & vbCrLf & "Error Number: " & Err.Number _
         & vbCrLf & "Error Description: " & Err.Description _
         , vbCritical, "Error!"
    Resume ThisMacro_exit

End Sub

Declaring 2 Variables At The Same Time In Python

I thought this was interesting:

import os
fileName, fileExtension = os.path.splitext('/path/to/somefile.ext') 

Since os.path.splitext returns a list of 2 items, you can assign those 2 list items to variables at the same time with the code above.

Tuesday, December 18, 2012

Path To Sharepoint

A lot of that stuff looks useful for adding functionality to Sharepoint. Also, this is one of the first public sites I've seen which use sharepoint (and it's not too bad). I saw it mentioned on this site:

Saturday, December 15, 2012

UTDesign - Xbee Claims vs Reality

The picture above shows some research done by some UTD students for their UT Design program.

Their results showed the specs claimed by Xbee modules were far superior to reality. They said they experienced an overwhelming amount of noise at about half of the rated distance and both the peak and idle current ratings were inaccurate.

Thursday, December 13, 2012

Wednesday, December 12, 2012

Raspberry Pi - Mining Bitcoins

Rather than letting my Raspberry Pi lay dormant in its cabinet at a data center, I've decided to use it for mining bitcoins.

I followed these instructions:

I'm using Deepbit as the pool, but I'm not 100% sure what a pool is or if there are better pools out there.

Update: In about 5 days, I have only mined 0.00003898 BTC.

Tuesday, December 4, 2012

Stop IE Alert Messages

The following snippet of Jquery will prevent alerts from showing in internet explorer:

if ($.browser.msie) { window.alert = function() { }; };

It detects if the browser is IE, then disables the alert function with a blank if it is IE. The alert happens only in IE, that's why it checks to see if the browser is IE.

I did this because there is some code I can't change on a sharepoint page which is causing an alert (which doesn't actually cause any real issues). Adding this code to the part of the page I can change will stop the error.

About the alert:
It says "Hit error fn!" and it happens in the following span after an ajax call fails: <span id="ctl00_LogUserActivity1">

It's definitely a hack, but it works so far.

Wednesday, November 28, 2012

Raspberry Pi Webserver w/ Wordpress Slow

I installed the LAMP stack on a Raspberry Pi, then moved a small Wordpress site to it. It then got plugged into a fast connection at a data center.

Before the move (shared hosting webserver at Siteground):

  • 1 second load times on the main page
After the move (Raspberry Pi):
  • 8-9 second load times on the main page
  • 5 second load times on single pages
The Pi does a good job at displaying static pages, but it does not run more intensive things like a CMS quickly enough.

Tuesday, November 27, 2012

LAMP Stack Ubuntu

It's crazy easy to install the LAMP stack on ubuntu with this command:

sudo apt-get install lamp-server^

Monday, November 26, 2012

SPJS Charts - Dynamically Select Filter Item

I've been using SPJS charts to make google charts with data from sharepoint lists. If you use a custom drop-down filter, you may want to dynamically select items in the drop-down like I did.

An example: You're using a drop-filter which filters the results by week, but you always want it to select last week.


function manualLoad(){
loadManually = false;

Date.prototype.getWeek = function() {
     var onejan = new Date(this.getFullYear(),0,1);
     var today = new Date(this.getFullYear(),this.getMonth(),this.getDate());
 var dayOfYear = ((today - onejan + 1)/86400000);
 return Math.ceil(dayOfYear/7)

$("#MyChart1_CustomFilterSelect_Week").val(new Date().getWeek()-1).change();

Tuesday, November 13, 2012

2nd Place - Ericsson & North Texas Food Bank Hackathon

The "Hackathon" was a programming competition sponsored by Ericsson to solve some of the North Texas Food Bank's problems.

Here's a link to our project:

It's a scheduling system that allows people to see which days need more volunteers, then sign up to volunteer. The coolest part is that it will call people with a prerecorded message reminding them of their appointment.

Calculate Weeks In Sharepoint


This is a modified version of this formula which didn't give me the correct week number (maybe due to regional settings?): 

It matches the number of weeks calculated in excel and all the calculators I could find on the internet.

Update: I also needed to add a 0 before the "Week" if the number is less than 10, because it will cause an error in sorting otherwise.

Here's the formula to add a 0 if the number is less than 10:
=IF((INT((Date-DATE(YEAR(Date),1,6)+(TEXT(WEEKDAY(DATE(YEAR(Date),0,1)),"d")))/7)+1)<10,"0"&(INT((Date-DATE(YEAR(Date),1,6)+(TEXT(WEEKDAY(DATE(YEAR(Date),0,1)),"d")))/7)+1),(INT((Date-DATE(YEAR(Date),1,6)+(TEXT(WEEKDAY(DATE(YEAR(Date),0,1)),"d")))/7)+1))&" "

(Note: the &" " part forces it to be a string rather than a floating point value)

Thursday, November 1, 2012

Impressive Javascript

"D3.js is a JavaScript library for manipulating documents based on data. D3 helps you bring data to life using HTML, SVG and CSS. D3’s emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation."

Thursday, October 25, 2012

Google Charts - GeoMap vs GeoChart

GeoMap - The map is rendered in the browser using an embedded Flash player.

GeoChart - Rendered using SVG

I noticed the GeoChart loads faster (at least in Chrome).

Wednesday, October 24, 2012

Monday, October 22, 2012

Friday, October 19, 2012

PHP Date Variables

That's a helpful post for controlling the output of PHP's date().

Difference Between Echo and Print In PHP

"echo can print more than 1 argument, print can only print 1 argument."

Triple Equals Sign In Php

Since PHP uses $ to declare variables (and not int, etc), one can run into issues with an if statement being unintentionally true.

For example, 0 == null.

The triple equals sign (===) allows you to prevent these cases by only returning true if the two inputs are not the same type.

So, 0 === null is not true. Also, 0 === "0" is not true either.

Monday, October 15, 2012

SQLSRV30.EXE is not a valid Win32 application

If you want to install the PDO drivers for PHP 5.4, you will need to extract SQLSRV30.EXE with Winrar.

Since I was using EasyPHP, I needed to extract the files into the following directory (there's also another php directory in EasyPHP, not sure why, but it's worth adding the files under "ext" there too): C:\Program Files\EasyPHP-12.1\php\php546x120827090829\ext

You will also need to add the following lines to your PHP.ini file under PHPExt:


Friday, October 12, 2012

Managing SQL Server 2008 with Management Studio 2005

When you google "SQL Management Studio", one of the first things that comes up is this (the 2005 version):

I recommend not installing 2005 if you have SQL Server 2008 Express installed! You will not be able to manage your 2008 server, and you will need to uninstall management studio to install the 2008 version here:

Friday, September 28, 2012

Get Folder Path From User Input

This is some very useful code from Stack Overflow which allows the user to select a folder in VBA and reads the folder path into a variable. I'm currently making a macro which opens several XML files in a folder, and this will help users to input the folder where those XML files are located:

Sub SelectFolder()
    Dim diaFolder As FileDialog

    ' Open the file dialog
    Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
    diaFolder.AllowMultiSelect = False

    MsgBox diaFolder.SelectedItems(1)

    Set diaFolder = Nothing
End Sub

Monday, September 17, 2012

VBA - Delete Worksheet With A Specific Name If It Exists

Application.DisplayAlerts = False 
On Error Resume Next 
On Error Goto 0 
Application.DisplayAlerts = True 

  • The code between "On Error Resume Next" and "On Error Goto 0" will be skipped if an error is generated. 
  • It also won't display the error to the user because of the code on line 1 (Application.DisplayAlerts = False).
  • "ThisWorkbook" will need to be declared.

Friday, September 14, 2012

Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object

If you get this error when you just type "java" into the command prompt, then it can be solved by typing "PATH=C:\Program Files\Java\jdk1.7.0_06\bin" (the folder of your java.exe).

Tuesday, August 14, 2012

Modifying PhoneGap Childbrowser View

In IOS, removing the back/forward, refresh, and history buttons from ChildBrowser requires opening its .xib file.

I removed everything except the done button:

Childbrowser Plugin

I thought that was a really good guide for getting started on Phonegap's Childbrowser plugin.

I'm using it to open PDFs from phonegap.

Tuesday, August 7, 2012

My First Stack Overflow Answer

I use Stack Overflow a ton, and I'm going to try to make more of an effort to contribute.

I was having trouble scrolling horizontally with the iscroll plugin, and I solved it by enabling the hScroll option (which I thought should have been enabled by default). I use iscroll's zoom function to enable zooming on a single div, while the rest of the page does not zoom.

SigPad API

I had difficulties getting Thomas J Bradley's HTML5 Signature Pad to let me to use its API without resetting the field. This Github issue explains a workaround:

He is saving the signature, declaring the api variable, then regenerating the signature.

I needed to use the .getSignatureImage() api function which allows me to turn the signature into a base64 string so I could store the signature in a database.

Tuesday, July 24, 2012


The article in the link above describes the process of adding inline HTML to PHP code instead of "echo '<html>';". It seems like it's much faster to not process each echo statement with PHP.

This is definitely a big "oh!" moment for someone still learning PHP.

Jquery Mobile - Only Load Once

If you only want something to load once, you can use the "pageinit" event.

Here's an example of some code with "pageinit":

$(document).delegate("#yourPage", "pageinit", function(event) { alert( "ALERT!"); });

The code above would not run if you visited the page again.

Monday, July 23, 2012

Make Phonegap Responsive

The following was absolutely mandatory for me to get my phonegap app to be responsive:

Without modification, Phonegap will wait for a "double-click" after the user taps. This results in a noticeable delay. With the plugin above included, it removes the delay.

Other plugins I tested wanted me to use selectors for each element I didn't want delayed.

Monday, July 16, 2012

Prevent Scrolling

The above link is the most simple solution I've found to prevent phone gap from scrolling outside of the bounds.

Thursday, July 5, 2012

Using Quotes In mysql_fetch_array()

According to this blog post:

mysql_fetch_array() can be sped up dramatically by including quotes, like this:

 $result['2'] rather than this $result[2]

I just changed my code to use quotes, and I haven't noticed a big speed increase (that's probably not where the bottleneck is).

Edit: This is probably misleading according to the good people at stackoverflow.

Tuesday, July 3, 2012


I'm really impressed with sisyphus.js and its usage of HTML5 localStorage. It makes it so users won't need to re-enter data into a form when they close the window.

It's super easy to implement, you only need to include the following in your header:

<script type="text/javascript" src="sisyphus.min.js"></script>

And, you will need to activate it on the form you want to save with something like this:


Tuesday, June 26, 2012

Write To Closest Div (with certain class)

The following code makes it so I don't have to mention specifically what page needs to load before a script runs. This is good for having the same function on several different pages in Jquery Mobile.

var pageId = $(this).closest('div.diagramPage').attr('id');

$(document).delegate(pageId, 'pageshow', function() { }

I included the class because I don't want to end up moving code around and having it write to a different div.

Monday, June 18, 2012

Fixing: "The requested URL /jquery-1.6.3.min.js was not found on this server."

In Wordpress, the following is the error message that occurs at the top of the page:

Not Found

The requested URL /jquery-1.6.3.min.js was not found on this server.

I fixed this error by editing the all-in-one SEO plugin's code (all_in_one_seo_pack.php). I'm pretty sure the following part of the code is the culprit:

 $url = ""; 
 $ch = curl_init();  
 $timeout = 5;  
 $data = curl_exec($ch);  
 echo "$data";

I tried changing it to something else, like: However, it just prints the entire contents onto the page.

The solution: Switch from the Pro 1.72 version of All-In-One SEO to the newest unpaid version.

Jquery Mobile - Display Loading Message

I've been displaying the ajax loading message when loading a php file (especially when there's a chance it won't run instantly).

I've been doing the following:

$.mobile.showPageLoadingMsg ();
$.mobile.hidePageLoadingMsg ();

"showPageLoadingMsg" will start to display the ajax loading message and "hidePage~" will close it. The stuff in the middle loads what the php file returns into a div, then creates DOM contents for it with the trigger('create') function.

Thursday, June 14, 2012

Best Jquery Mobile Datebox Plugin

The currently reigning champion of datebox plugins for Jquery Mobile:

Jquery Mobile - Close Jqm-Datebox When Dialog Closes

// this will make sure the datebox closes when the dialog closes
$(document).delegate('#closeButton', 'click', function() {

Make sure your #closeButton is the same as the button which closes the dialog.

Wednesday, June 13, 2012

TodoMVC with MySQL Database

This project is a modification of the TodoMVC (used to sample how a language is structured by making a To-Do list). It adds database support and ends up being a very cool To-Do list.

Good Jquery Mobile Blog Post

Just got finished reading the following blog post:

Most of it's obvious, but it's definitely on my list of good blog posts for Jquery Mobile beginners.

Reminds me how Jquery Mobile needs an official "Best Practices" document.

Monday, June 11, 2012

Loading Scripts Dynamically In Jquery Mobile

At first, I loaded all of my scripts in the header (even when the scripts weren't needed when the page was being loaded).

I found this website that partially explained how to load scripts when the page loads. However, Jquery Mobile needs to use the delegate function to load the script when a page is showing.

I copied the function from the website above:
function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("src", filename)
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 if (typeof fileref!="undefined")
Now, you need to add code to the top of the data-role="page" where you want the script to load:
$(document).delegate('#page', 'pageshow', function() {
 loadjscssfile("your.css", "css")
 loadjscssfile("your.js", "js")

Tuesday, June 5, 2012

Best Jquery Calendar Plugin

FullCalendar can be found here:

I thought it looked the best and had the most API functions out of the HTML5 calendars I saw.

Jquery Add/Remove Class

Problem: In Jquery Mobile, I used the mobile.changePage (method) to switch pages. Now the button for the previous page is still blue.

Solution: Add Id's to the list items you'll be dealing with. Then use Jquery to remove the class "ui-btn-active" from the old button, and add the "ui-btn-active" class to the new button.

Here's the code:

Global Variables In Javascript

Problem: I had two different <script> (javascript) sections, and I was unable to pass a variable from one set of <script> tags to the other.

Turns out it doesn't have anything to do with the script tags, and I just needed to learn a bit more about scope in Javascript. Apparently global variables are a common thing (maybe still not a good practice?) and as long as a variable is used outside of a function.. You'll be able to access the variable anywhere on the page.

Solution: Take the variable outside of the function.

Jquery Serialize

I spent a while looking for a good way to pass variables from HTML to Javascript (ajax) to PHP. Turns out Jquery's serialize function is exactly what I needed.

Here's an example of the code:

//this will send all the inputs in the form to php with ajax
$('#form').submit( function() {
     var data = form.$('input').serialize();
          type: "POST",
          url: "process.php",
          data: data,
          success: function(msg){
          alert( "Your quote request has been submitted!" );
     return false;
} );

Also, you can use serializeArray()to get the data in a better format. Here's a picture of the console.log output: