Lazy Load v2 – delay image loading Nivo Slider v3

Nivo Slider is a great image slider which I recently implemented on one of my WordPress blogs, the problem with the current version is all images need to be loaded first prior to running the Nivo Slider JavaScript.

After a bit of searching I found a fork by Lee Powers named Lazy Load, the update was for an older version of Nivo Slider which didn’t support responsive images.

After a bit of copy and pasting I managed to port Lazy Load to the updated Nivo Slider version.

Find the fork on Github.

For an example of Lazy Load v2 with 100 images in a Nivo Slider head over to SonyaandTravis.com.

PHP eval equivalent to include

The PHP include statement includes and evaluates a specific file, not what if we want to modify that file first before including, i.e. a version template file.

Well this can be done with PHP eval.

I file is included as follows;

include myfile.php

Using eval, we can achieve the same as above as follows;

$inc = file_get_contents('myfile.php');
eval("?>".$inc);

VBA/VBS check if printer is installed

Here is a quick code snippet to determine if a printer is installed on a Microsoft Windows system;

MsgBox printerExists("Microsoft XPS Document Writer")

Function printerExists(str)
    printerExists = False
    Dim objWMIService
    Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

    Dim colPrinters
    Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

    Dim objPrinter
    For Each objPrinter In colPrinters
        If objPrinter.Name = str Then
            printerExists = True
            Exit For
        End If
    Next
End Function

PHP code to automatically bid/buy an eBay auction item

The following PHP code will automatically bid on an eBay item.

modify the following variables;

  • $username = “username”; //the eBay username
  • $password = “password”; //the eBay password
  • $item = 300712344201; //the item number
  • $bid =  0.01; //the  bid value in the item’s currency
<?php
	//modify the following

	$username = "username"; //the eBay username
	$password = "password"; //the eBay password

	$item = 300712344201; //the item number
	$bid =  0.01; //the  bid value in the item's currency

	//do not modify below

	//query the sign-in page
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_URL,"http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn");
	$ret = curl_exec ($curl);
	curl_close ($curl);

	//sign-in
	$post = "MfcISAPICommand=SignInWelcome&siteid=0&co_partnerId=2&UsingSSL=0&ru=&pp=&pa1=&pa2=&pa3=&i1=-1&pageType=-1&userid={$username}&pass={$password}";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS,$post);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_REFERER, "http://signin.ebay.com/aw-cgi/eBayISAPI.dll?SignIn");
	curl_setopt($curl, CURLOPT_URL, "http://signin.ebay.com/aw-cgi/eBayISAPI.dll");
	$ret = curl_exec ($curl);
	curl_close ($curl);

	if (strpos($ret, "Member id {$username}") === FALSE) {
		echo "Failed signing in.\r\n";
	} else {
		echo "Success signing in.\r\n";
	}

	//place the inital bid
	$url = "http://offer.ebay.com/ws/eBayISAPI.dll?MakeBid&item={$item}&maxbid={$bid}";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_URL, $url);
	$ret = curl_exec ($curl);
	curl_close ($curl);

	preg_match_all('/(?:value="([-0-9a-zA-Z]*)" *)?name="stok"(?: *value="([-0-9a-zA-Z]*)")?/', $ret, $regs);
	$stok = $regs[1][0];

	preg_match_all('/(?:value="([-0-9a-zA-Z]*)" *)?name="uiid"(?: *value="([-0-9a-zA-Z]*)")?/', $ret, $regs);
	$uiid = $regs[1][0];

	if (($stok) && ($uiid)) {
		echo "Success placing initial bid.\r\n";
	} else {
		echo "Failed placing initial bid.\r\n";
	}

	//confirm the bid
	$url = "http://offer.ebay.com/ws/eBayISAPI.dll?MfcISAPICommand=MakeBid&maxbid={$bid}&quant=1&mode=1&stok={$stok}&uiid={$uiid}&co_partnerid=2&user={$username}&fb=0&item={$item}";

	$curl = curl_init();
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20100101 Firefox/15.0.1");
	curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
	curl_setopt($curl, CURLOPT_COOKIEFILE, "cookies.txt");
	curl_setopt($curl, CURLOPT_COOKIEJAR, "cookies.txt");
	curl_setopt($curl, CURLOPT_URL, $url);
	$ret = curl_exec ($curl);
	curl_close ($curl);

	if (strpos($ret, "you're the first bidder") === FALSE) {
		echo "Failed placing final bid.\r\n";
	} else {
		echo "Success placing final bid.\r\n";
	}

	//for testing
	//$fh = fopen("testhtml.html", 'w');
	//fwrite($fh, $ret);
	//fclose($fh);
?>

VB functions for determining red/black numbers on roulette wheel

Here are two simple functions for calculating if a number falls on red or black on a roulette wheel, for the perfectionists that don’t want to use odd/even.

'isRed calculates if a number falls red on a roulette wheel
Public Function isRed(ByRef n As Long) As Boolean
    Select Case n
        Case 1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36
            isRed = True
        Case Else
            isRed = False
    End Select
End Function

'isBlack calculates if a number falls black on a roulette wheel
Public Function isBlack(ByRef n As Long) As Boolean
    Select Case n
        Case 2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35
            isBlack = True
        Case Else
            isBlack = False
    End Select
End Function

Batch GPX trace files to Open Street Map (OSM) with GpxUpload

A quick tutorial on how to upload multiple GPX trace files to Open Street Map, I use the Java class by Christof Dallermassl, alternatives can be found at OSM Wiki Batch Upload.

First download the Java source file from jgpxupload and compile it, I used online compiler from Innovation.

The following is the syntax that GpxUpload uses,

java -Dusername=thydzik -Dpassword=<password> GpxUpload "Auto 28-SEP-11 17.11.11" "" "Auto 28-SEP-11 17.11.11.gpx"

If you have a list of GPX files, use the following spreadsheet to create a batch file.

SplitExtended – improved VB split function with group characters

Based on SplitEx by Chip Pearson, SplitExtended is optimised to be over double the speed, with fixes and additional features;

Features over the standard VB Split are;

  • grouping characters, no longer split strings in quotes,
  • ignore consecutive delimiters, while preserving those in  grouping characters,
  • option to remove grouping characters, start and end quotes can be removed, and
  • double grouping characters inside a grouping character is converted to single grouping characters, double quotes inside quotes are converted to single quotes.

Download modSplitExtended.bas

Code here;

Option Explicit

'====================================================================================
' SplitExtended
' By Travis Hydzik
'
' Based on SplitEx by Chip Pearson http://www.cpearson.com/Excel/Split.aspx
'
' Improvements include;
' - over double the speed of SplitEx
' - doesn't remove double Delimiters in groups
' - double GroupChar in groups treated as escaped and converted to single
'====================================================================================
Public Function SplitExtended(ByRef InString As String, _
    ByVal Delimiter As String, _
    Optional ByVal GroupChar As String = vbNullString, _
    Optional ByVal IgnoreConsecutiveDelimiters As Boolean = False, _
    Optional ByVal DeleteGroupCharacters As Boolean = False) As String()

    Dim arr() As String

    Dim InGroupReplace As String
    Dim consectGroupReplace As String

    Dim S As String

    S = InString
    Dim i As Long, j As Long

    If LenB(S) = 0 Then
        'string is empty so return an unbound array (similar to original Split)
    ElseIf LenB(Delimiter) = 0 Then
        'Delimiter is empty so return an array with the first element the string
        ReDim arr(0)
        arr(0) = S
    ElseIf InStrB(1, S, Delimiter, vbBinaryCompare) = 0 Then
        'Delimiter is not found in the string, return an array with the first element of the string
        ReDim arr(0)
        arr(0) = S
    Else

        'find a unique character in string s, that isn't the Delimiter
        'it can be unique AND the group character as this means there won't be any grouping
        i = -1
        Do While LenB(InGroupReplace) = 0
            i = i + 1
            'the character is unique
            If InStrB(1, S, ChrW$(i), vbBinaryCompare) = 0 Then
                'the character is not the delimiter
                If StrComp(ChrW$(i), Delimiter, vbBinaryCompare) <> 0 Then
                    InGroupReplace = ChrW$(i)
                End If
            End If
        Loop

        'if DeleteGroupCharacters is enabled, it is common to double the GroupChar if that character is needed
        'replace all consecutive group characters with consectGroupReplace
        If DeleteGroupCharacters Then
            'only if there are consecutive GroupChar
            If InStrB(1, S, GroupChar & GroupChar, vbBinaryCompare) > 0 Then
                'find a unique character in string s, that isn't the Delimiter and isn't inGroupReplace
                Do While LenB(consectGroupReplace) = 0
                    i = i + 1
                    'the character is unique
                    If InStrB(1, S, ChrW$(i), vbBinaryCompare) = 0 Then
                        'the character is not the delimiter
                        If StrComp(ChrW$(i), Delimiter, vbBinaryCompare) <> 0 Then
                            'the character is not the GroupChar
                            If StrComp(ChrW$(i), GroupChar, vbBinaryCompare) <> 0 Then
                                consectGroupReplace = ChrW$(i)
                            End If
                        End If
                    End If
                Loop

                'once the character is found, replace all double GroupChar
                S = Replace(S, GroupChar & GroupChar, consectGroupReplace, 1, -1)
            End If
        End If

        'replace any Delimiter occuring in a group with inGroupReplace
        i = InStr(1, S, GroupChar, vbBinaryCompare)
        j = InStr(i + Len(GroupChar), S, GroupChar, vbBinaryCompare)
        Do While i > 0 And j > 0
            If j > i Then
                'mid$(s, 1, i) = Replace(mid$(s, 1, i), Delimiter, inGroupReplace, 1, -1, vbBinaryCompare)
                'mid$(s, j) = Replace(mid$(s, j), Delimiter, inGroupReplace, 1, -1, vbBinaryCompare)
                Mid$(S, i, j - i) = Replace(Mid$(S, i, j - i), Delimiter, InGroupReplace, 1, -1, vbBinaryCompare)
            Else
                S = Replace(S, Delimiter, InGroupReplace, 1, -1, vbBinaryCompare)
            End If

            i = InStr(j + Len(GroupChar), S, GroupChar, vbBinaryCompare)
            j = InStr(i + Len(GroupChar), S, GroupChar, vbBinaryCompare)
        Loop

        'remove any consecutive delimiters, iteratively
        If IgnoreConsecutiveDelimiters Then
            Do While InStrB(1, S, Delimiter & Delimiter, vbBinaryCompare) > 0
                S = Replace(S, Delimiter & Delimiter, Delimiter, 1, -1, vbBinaryCompare)
            Loop
        End If

        'perform the split
        arr = Split(S, Delimiter, -1, vbBinaryCompare)

        'loop through the array and restore the special characters
        For i = 0 To UBound(arr)
            If InStrB(1, arr(i), InGroupReplace, vbBinaryCompare) > 0 Then
                arr(i) = Replace(arr(i), InGroupReplace, Delimiter, 1, -1, vbBinaryCompare)
            End If
            If DeleteGroupCharacters Then
                If InStrB(1, arr(i), GroupChar, vbBinaryCompare) > 0 Then
                    arr(i) = Replace(arr(i), GroupChar, vbNullString, 1, -1, vbBinaryCompare)
                End If
                If InStrB(1, arr(i), consectGroupReplace, vbBinaryCompare) > 0 Then
                    arr(i) = Replace(arr(i), consectGroupReplace, GroupChar, 1, -1, vbBinaryCompare)
                End If
            End If
        Next i
    End If

    SplitExtended = arr

End Function