My own MySQL class for C# .NET

Tagged:  

While I was working on some projects I needed an easy abstract access to the data that was in the MySQL database. So I wrote this class, to be used where I felt like to.

Of course it needs a mysql .NET connector (driver).

You can get the full Visual Studio zipped project archive right here.

 

You can use the code in your program like this:

test1.cs

using System;
//using System.Collections.Generic;
using System.Collections;
//using System.Linq;
using System.Text;

namespace Project1
{
    class test1
    {
        static void Main(string[] args)
        {
            // change this of course
            MySQLConnection sqlserver = new MySQLConnection("server=DBADDRESS; user id=DBUSER; database=TESTDATABASE; password=DBPASS; ", true);

            // and this...
            string table = "`TESTDATABASE`.`_testtable`";

            sqlserver.SqlExecute("CREATE TABLE IF NOT EXISTS " + 
                table + " (  " +
                "`id` INT NOT NULL AUTO_INCREMENT, " +
                "`stuff` VARCHAR( 256 ) NOT NULL, " +
                "PRIMARY KEY ( `id` ) " +
                ") ENGINE = MYISAM", null);

            sqlserver.SqlExecute("TRUNCATE " + table, null);

            sqlserver.SqlExecute("INSERT INTO  " + table + 
                " (`id` ,`stuff`)" +
                "VALUES (NULL , 'aa'), (NULL , 'bb') ", null);

            Hashtable sql_param = new Hashtable();
            sql_param.Add("stuff1", "cc");
            sql_param.Add("stuff2", "dd");

            sqlserver.SqlExecute("INSERT INTO " + table + 
                " (`id` ,`stuff`)" +
                "VALUES (NULL , @stuff1), (NULL , @stuff2) ", 
                sql_param); // No quotes!

            ArrayList somedata = new ArrayList();
            somedata = sqlserver.SqlFetchList("SELECT stuff FROM " + 
                table, null);

            foreach (string d in somedata)
            {
                Console.WriteLine("'" + d.ToString() + "'");
            }
    
        }
    }
}

The fastest path between to points is a straight line!

Tagged:  
I like google maps, it's a good product. But sometimes I don't trust them ;-)

Using SVN over SSH on non default ports (for Windows clients)

I had a need to use SVN over encrypted line, so after some research I came up with this solution. I won't go into details on how to install SVN or SSH server, I assume you already got that working. This small guide was written for one of the users, that needed to configure their SVN client to use SSH on non standart port, so here it is:
  1. Download the required SSH software for Windows (I assume you already have TortoiseSVN). Clicky 1.
  2. Use the SSH keys (not covered on how to make them in this mini-guide) Clicky 2.
  3. Change network setting in TortoiseSVN, to use different port for SSH:
    <path_to>\bin\TortoisePlink.exe -P <custom_ssh_port> -l <working_ssh_username>
    
    Clicky 3.
  4. Use the checkout function. The URL will need to have to be a little bit different than usual:
    svn+ssh://<hostname>/<full_path_of_svn_on_the_server>
    
    Clicky 4.
  5. And that should be working! Clicky 5.

Changes and moves

Tagged:  
Finally all my exams and courseworks are done. And today I'm moving to a new flat. I'm not sure about further academic studies, because I'm quite keen on working full time. Exciting.

Codemasters Connect event

Tagged:  
I am glad Tomas invited to join him at Connect, which was a Codemasters Online games' (MMO's) 2-day premier event. It consisted of LotR, D&D online, RF online, Archlord and Jumpgate Evolution (which as of this writing is still beta) presentations ant playtime. I am not currently an active player, but I had good time in the event. After the presentation of Jumpgate Evolution to the public, we were invited to play it in the ground floor. So we went, stood there for half an hour in the queue, filled some feedback on the Jumpgate's logo and DVD cover design and started playing it. We were told that there is a PvP posibillity, but could not find such option/action, and got a little bit dissapointed. Jumpgate Evolution differs from EVE online, that you control your spacecraft from the first person view directly (similar to Freespace or Descent) other than that it is still not a finished product and it's difficult to evaluate it after playing just a few hours. Anyway I did enjoy playing it with 2 joysticks, which was kind of cool :) Had a little bit of LARP action. Killed some things. Waiting for photos from those people. But the most memorable event I guess was the Colin McRae Dirt competition. The rules were if you finish the time trial:
  1. under 4 minutes, you get LotR gold edition.
  2. under 3 min 30 second you win the Xbox 360!
We signed up just for the xbox. After some tries, I ended up "just" winning the LotR game. But my friend Tomas was the best driver of all, he beat time trial in just under 3:30.69 Just a little bit too slow! A shame nobody won the Xbox 360, but it was fun, especially hearing the commentator getting excited about the best time! :) Ok here are some pictures of the event.

ThinkPad X300. Do want!

For mobile computing I wish I had the ThinkPad X300 :-) Review, more.

Small solution for server statistics

Purpose

Once I needed small statistics collecting and displaying solution, that I could access from my web browser on a server where PHP was not an option. Because of that Cacti was not an option. So I quickly hacked this piece of shi^H^H^H script :-)

I'm not going to explain how to setup collectd, a statistics gathering daemon which I use for myself.

Output

Sample output:

Requirements

  • collectd (for collecting data to RRD)
  • rrdtool (for RRD libraries and graphing tool)
  • simple httpd server, e.g. lighttpd (don't worry Apache works too ;)

(It's also possible to use SNMP and write data to RRD yourself)

Little step by step guide of my crappy script

1) These files should be placed under /opt/graphrrd/ Or if you want in another place (e.g. your home dir), you'll have to substitute corresponding lines in scripts.

2) The output by default will be placed in /var/www/stats/, so create that dir before running any script.

3) Some default values are in /opt/graphrrd/_values check them out.

4) To make sure everything is OK run /opt/graphrrd/graphall If you see any errors/warnings, then act according to them. Else go to step 5.

Google vs. Chuck Norris

Who doesn't know about legendary Chuck Norris and his famous reverse roundhouse kick! If you don't, then trying to find him on Google's search engine might be helpful, or wouldn't it? Let's try, open www.google.com and type in "find chuck norris". Now press I'm feeling lucky button.








Spoiler

Ok, it's not a real google page, notice the URL. But still funny, kudos to author :-)

HP Pavillion dv6525em setup with Ubuntu

Several months ago I bought myself a HP Pavillion dv6525em, because my ageing Apple G4 Powerbook had become simply to weak for today's computing requirements (needles to say I was unable to play Q3A and RA2 with my housemates!

Of course it came pre-installed with Windows Vista, which was "upgraded" to XP several weeks later by me, which I consider is much better for my current needs, where I need raw power (for games and later video decoding/encoding needed for my university's final project).

Enough intro! Let's get down to business. After installing Ubuntu to this laptop, everything worked out of the box (including video acceleration of the desktop, so I was amused by Compiz-fusion:), except Broadcom wireless drivers were missing and also my laptop speaker weren't muted when I insert headphones.


The solution for wireless


For this to work, I use ndiswrapper, which is in Ubuntu's main repository. Just:

sudo apt-get install ndiswrapper ndiswrapper-utils

The actual drivers are from Windows system, I have attached them for convenience wifi.tar.bz2. Download them and extract to temporary place, we will need only the INF file:

sudo ndiswrapper -i bcmwl5.inf
sudo ndiswrapper -m

Our wireless driver is now installed but not working just yet. It's currently being blocked by another driver that is trying to run, so we need to block this other driver:

sudo sh -c  'echo "blacklist bcm43xx" >> /etc/modprobe.d/blacklist'

Now let's add it to the modules list.

Hello World!

So finally I decided that I need a public place on this World Wide Web. And this is going to be fun! I hope :-) To not make my post absolutely useless I'll put some info about my setup of this web site:
  • hosted on dedicated www.kiberzona.lt server in Lithuania, which I'm taking care of
  • this machine is running a stable release of FreeBDS happily with Lighttpd + MySQL + PHP5
  • on top of everything there is an amazing Drupal CMS
  • and for user visible interface I use a great looking theme called Celju with my own customizations
Nice, isn't it?
Syndicate content
---