Posts

VB.Net Cross Thread Events in WinForms

Today I quickly did a proof of concept on integrating a third part component into a winforms application and had to figure out how to raise events on the Windows Forms UI thread from a different one. There are plenty of examples of doing this in C# but they didn't quite translate to VB.Net. Although a BackgroundWorker may have worked I had some more complex requirements. Therefore I slightly tweaked a C# cross thread example on stackoverflow and combined it with another example of building a custom event. Here is what I came out with. I have to investigate better ways of doing this but since there is a lack of any VB.Net examples I thought I would post one. Imports System.ComponentModel Imports System.Threading Public Class CrossThreadingExample Private dummyThread As Thread Private ReadOnly crossThreadEventList As New List(Of CrossThreadEventHandler) Public Delegate Sub CrossThreadEventHandler(sender As Object, e As CrossThreadEventArgs) Public Custom E...

Querying IIS Log File Information Easily

Microsoft has a command line tool called LogParser that can easily be used to execute SQL statements against log files. The tool is extremely handy when there is problem with a web service or site hosted by IIS. For example to see if a rogue consumer of your web service is doing something silly like looping through and flooding it with calls you can query the most called web service by IP address by issuing: .\LogParser.exe -i:W3C " select count(*), date as date, cs-uri-stem, c-ip from \\servername\logs\current\* group by date, cs-uri-stem, c-ip having count(*) > 500000 " -rtp:-1 This will return a nicely formatted result like so: COUNT(ALL *) date cs-uri-stem c-ip ------------ ---------- ----------------------------- ------------- 510832 2013-07-11 /ExampleServices/Test.asmx 10.1.1.1 535199 2013-07-11 /ExampleServices/Example.asmx 10.1.1.2 Log parser...

Getting the Lenovo Yoga wireless driver working in Fedora 18

If you are like me you installed Fedora 18 off the live CD only to find that you can't do anything because the wireless card does not work by default. To get wireless working the first step is to install the build tools needed to install the driver. The easiest way to do this is to download the install DVD to a USB thumb drive. Once you plug it into the Yoga, Fedora will mount the drive automatically. Figure out where it mounted by going to Dolphin or whatever file manager you use and viewing the path to the drive. Now go into your yum repos and temporary change the yum repository to point to the live dvd image. [richie@localhost ~]$ su - Password: [root@localhost ~]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# gedit fedora.repo change from [fedora] name=Fedora $releasever - $basearch failovermethod=priority #baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/ mirrorlist=https://mirrors.fedoraproject.org/metalink?...

Selenium 2 Java Quick Setup

I had a seemingly random issue with a website where it would fail one out of x times. Since I haven't used Selenium 2 yet I thought I would run a Selenium test. To get started in Selenium 2 and Java the quickest way is to use Selenium IDE and generate some tests. Then use the File -> Export Test Case As -> Java / JUnit 4 WebDriver Backend. After the test is created then just drop it into Netbeans or Eclipse. The first stumbling block I ran into was that I needed Both Selenium Client and Selenium Server Jars added. Without the Selenium Server Jar, I saw an unhelpful error that stated: "com/google/common/base/Function". After adding those 2 Jars, if you don't use the Eclipse or Netbeans test runners, make sure to add the JUnit Jar. Then you can run your test. Here is a shell that does nothing but run a test that was outputted from Selenium IDE. package webdriversample; import com.thoughtworks.selenium.Selenium; import org.junit.After; import org.junit.Asser...

Setting up Apache To Work with PHP and Zend Framework in Fedora for Development

To get started the first thing we need to do is install Apache and PHP. yum install httpd php You can setup Apache to run in any users public_html directory but I am the only one using my computer and I like to name my websites directory whatever I want so we have to create the folder and give Apache permissions to it: mkdir ~/websites chmod 711 /home/accessrichard chmod 755 /home/accessrichard/websites After that we have to set Apache to redirect our localhost traffic to the above website directory. Create your own Apache config file in /etc/httpd/conf.d touch /etc/httpd/conf.d/accessrichard.conf Add something similar to the following in the file we just created replacing your home directory name and your website folder name as appropriate. In the below example I am setting up 2 different websites, demo.dev and demo2.dev. NameVirtualHost *:80 < VirtualHost *:80 > ServerName demo.dev DocumentRoot /home/accessrichard/websites/demo/public SetEnv APPLICATION...

Set MySql Timezone information on Linux

In order to use the MySQL CONVERT_TZ() function on Linux which converts a datetime from one timezone to another, MySql needs timezone definitions and offsets which is dependent on the operating system in use. Otherwise CONVERT_TZ() returns NULL values. To do this on Linux, use MySQL's utility script, " mysql_tzinfo_to_sql ". Example usage: mysql_tzinfo_to_sql /usr/share/zoneinfo This returns a sql script to run to setup the timezone information. The following will setup the timezone information directly: mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql Now you can view your timestamps in local timezone: SELECT CONVERT_TZ('2010-01-02 00:00:00', 'UTC', 'America/Chicago' );

Java equivalent to MySql and PHP SHA1

The following code snippet demonstrates Java's equivalent to PHP and MySql's SHA1 function: import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class SHA1Test { public static void main(String[] args){ String hashStr = null; String password = "password"; try { MessageDigest md = MessageDigest.getInstance("SHA-1"); md.update(password.getBytes()); BigInteger hash = new BigInteger(1, md.digest()); hashStr = hash.toString(16); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } System.out.println(hashStr); //outputs: 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 } } mysql> select sha1('password'); +------------------------------------------+ | sha1('password')                         | +------------------------------------------+ | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 | +----------...