Saturday, October 26, 2013


So a few days ago I was browsing a site

and I wanted to download the images, but there are like 72 of them and I don't want to right click each one and save them. So I was thinking since I could use wget, but I don't want to download the whole site. I just want the pictures of this sweet looking bike! So I took a look at the URL for the images and sure enough they are all using a simple naming scheme (e.g. speed_001.jpg). So what immediately comes to mind is a bash script with a for loop calling wget to download all the images for me (because you know as programmers we are lazy).

for ((i=1; i<=NUM; i++)) {

    if [ $i -lt 10 ]
        wget ${ADD}
        wget ${ADD}

I'm not saying that this is the only way to do this, it's just what came to mind when faced with the problem.

Thursday, September 19, 2013

Getting Alt Text from IMG tags in HTML using Pattern Regex - Java

I was given the task to retrieve alt= from an img tag inside an html string. Here is an example:

<div class="rc_release_list_item_picture">
 <a href="/release/fatboy-slim-and-riva-starr/21683/eat-sleep-rave-repeat/"><img width="87" height="87" border="0" src="" alt="Fatboy Slim and Riva Starr - Eat, Sleep, Rave, Repeat" title="Fatboy Slim and Riva Starr - Eat, Sleep, Rave, Repeat" /></a>

I used the Pattern and Matcher Class provided by the java.util package. The following is a sample of quick main I built to achieve my task:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

 * User: GKproggy
public class Main
    private static String testStrings = "<div class=\"rc_release_list_item_picture\">\n" +
            " <a href=\"/release/fatboy-slim-and-riva-starr/21683/eat-sleep-rave-repeat/\"><img width=\"87\" height=\"87\" border=\"0\" src=\"\" alt=\"Fatboy Slim and Riva Starr - Eat, Sleep, Rave, Repeat\" title=\"Fatboy Slim and Riva Starr - Eat, Sleep, Rave, Repeat\" /></a>\n" +
    public static void main(String[] args)
        String regexPattern = "<img[^>]*alt=[\"]*([\\w\\s-.:\\/,]+)[\"]*[^>]*/>";
        Pattern p = Pattern.compile(regexPattern);
        Matcher m = p.matcher(testStrings);


Hope this was a quick help to get an idea how to use regex to retrieve info you want from raw HTML.

Tuesday, July 30, 2013

GKproggy Video Poker 2.0 is out on Google Play

The new version of 2.0 features:
  • Custom bet option to enter any amount. 
  • Google Play Game Services is available for you to play and unlock achievements as well as post your tournament score to show off your winnings on the leader board. Check it out on Google Play

Monday, February 18, 2013

XNA Visual Studio 2010 Direct3d Issue - Solved

I was trying to run some code in Visual Studio 2010 using XNA framework, but I was required to run using HiDef profile. Running my code in Refresh profile was not working due to some buffer indices issue. Here is a screenshot of error I was seeing after building project and trying to debug when setting profile to HiDef:

I looked all over the internet for error, "No suitable graphics card found. Could not find a Direct3D device that supports the XNA Framework HiDef profile...." I kept finding suggestion to change project property to refresh, but this was not good enough. 

Here is how I solved my issue. I was trying to build from a laptop (ASUS) which has two graphic cards, Intel and Nvidia. Turns out something is up with Intel graphics drivers and when you run Visual Studio 2010 it throws the problem above. When I tried to run VS2010 by right clicking on desktop application on icon and choosing "Run with graphics processor" -> "High performance NVIDIA processor", my project compiled using HiDef profile.

Hope this helps you guys looking to run HiDef profile.

Saturday, January 26, 2013

Draw Text on Canvas with Font Size Independent of Screen Resolution - Android

I will show how to draw text with a font size independent of screen resolution on to a canvas.
First we need to create an XML and place it in res/values. Call the file myFontSize. The following is the content of the file


Here is a sample use and how to implement.
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;

public class MainActivity extends Activity
 Paint paint;

 protected void onCreate(Bundle savedInstanceState)
  paint = new Paint();
  View test = new TestView(this);


 public class TestView extends View

  public TestView(Context context)
   setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

  protected void onDraw(Canvas canvas)
   int size = getResources().getDimensionPixelSize(R.dimen.myFontSize);
   canvas.drawText("HELLOOOOOOOOOOOOOO!", 0, size, paint);

The magic happens on the call to getResources().getDimensionPixelSize(..). This function grabs your set font size (in this case 20sp) and returns it as an appropriate size to give to your paint. Paint is the attributes which will tell the canvas what to do to the provided text.

You should see the following on different resolutions