Bruno Terkaly wrote 11 lessons (more to come) on the art of debugging in MS Visual Studio.Net 2008. Very interesting and a must read to catch some tips! Did you know that MS Visual Studio.Net can debug Javascript? :-)
Visit his blog for the 11 lessons or this list that list the first 10 lessons.
Have fun!
Monday, March 23, 2009
Saturday, March 14, 2009
Weekly Source Code: Ruby Setting Utility Class
Its a general task to store application settings so I wrote my own for the Ruby programming language
How to use:
Save the SettingUtil.rb file so that your application code can find it.
Add:
require 'SettingsUtil'
include SettingUtil
Save Example:
require 'SettingsUtil'
include SettingUtil
setting = Settings.new # create the settings object
setting.values = {"jabber_notifyme" => "true", "jabber_jid" => "lenniedg@gmail.com", "jabber_password" => "", "jabber_to" => "lenniedg@gmail.com"}
setting.save
puts setting.jabber_to
to save you need to set the values accessor which is a hashset then call the save method.
Load Example:
require 'SettingsUtil'
include SettingUtil
setting = Settings.new
puts setting.values["jabber_to"]
when creating a new object of Settings (remember its in the SettingUtil module) it will load the previous saved settings else you can just call load method directly.
Note:
There are 2x ways to get the settings value:
puts setting.jabber_to
OR
puts setting.values["jabber_to"]
in both cases it reads the setting of "jabber_to" from the values hashset.
If it can't find the setting the first option will return "none" by default where the second option will return a nil reference.
By default it save settings into a settings.config file, you might want to change that if you wish.
The source:
#
# Store application settings
# Settings get marchalled to a file and then loaded, you can refer to settings
# by getting them from the values accessor directly or calling a method
#
# Author: Lennie De Villiers
# Created: 12/03/2009
module SettingUtil
SettingsFileName = "settings.conf" # constant with the file name
attr_accessor :values
class Settings
def initialize()
values = {}
load()
end
def load()
if File.exists?(SettingsFileName)
f = open(SettingsFileName)
temp = Marshal.load(f)
self.values = temp.values
end
end
def save()
open(SettingsFileName, "w") { |f| Marshal.dump(self, f) }
end
def method_missing(method_name, *args)
if values != nil && values.key?(method_name.to_s)
return values[method_name.to_s]
else
return "none"
end
end
end
end
How to use:
Save the SettingUtil.rb file so that your application code can find it.
Add:
require 'SettingsUtil'
include SettingUtil
Save Example:
require 'SettingsUtil'
include SettingUtil
setting = Settings.new # create the settings object
setting.values = {"jabber_notifyme" => "true", "jabber_jid" => "lenniedg@gmail.com", "jabber_password" => "", "jabber_to" => "lenniedg@gmail.com"}
setting.save
puts setting.jabber_to
to save you need to set the values accessor which is a hashset then call the save method.
Load Example:
require 'SettingsUtil'
include SettingUtil
setting = Settings.new
puts setting.values["jabber_to"]
when creating a new object of Settings (remember its in the SettingUtil module) it will load the previous saved settings else you can just call load method directly.
Note:
There are 2x ways to get the settings value:
puts setting.jabber_to
OR
puts setting.values["jabber_to"]
in both cases it reads the setting of "jabber_to" from the values hashset.
If it can't find the setting the first option will return "none" by default where the second option will return a nil reference.
By default it save settings into a settings.config file, you might want to change that if you wish.
The source:
#
# Store application settings
# Settings get marchalled to a file and then loaded, you can refer to settings
# by getting them from the values accessor directly or calling a method
#
# Author: Lennie De Villiers
# Created: 12/03/2009
module SettingUtil
SettingsFileName = "settings.conf" # constant with the file name
attr_accessor :values
class Settings
def initialize()
values = {}
load()
end
def load()
if File.exists?(SettingsFileName)
f = open(SettingsFileName)
temp = Marshal.load(f)
self.values = temp.values
end
end
def save()
open(SettingsFileName, "w") { |f| Marshal.dump(self, f) }
end
def method_missing(method_name, *args)
if values != nil && values.key?(method_name.to_s)
return values[method_name.to_s]
else
return "none"
end
end
end
end
Tuesday, March 10, 2009
Weekly Source Code: Twitter IM Notification
Twitter has become a very populare social website where you tell the world what your doing in 140 characters.
You can always follow me on Twitter
Since I've started to teach myself the Ruby dynamic programming language you can use this Ruby script to send yourself notification to Google Talk when a friend post a message to Twitter.
Steps:
1) Download Ruby
2) Install Ruby and setup a path to C:\Ruby\bin
3) Install the twitter gem: gem install twitter
4) Install the Jabber gem: gem install xmpp4r
5) Update the script by adding your Twitter username and password, Google Talk username (like lenniedg@gmail.com), password and notification address (like lenniedg@gmail.com)
6) run the script: ruby TwitterIMNotify_share.rb
I love Ruby! :)
You can always follow me on Twitter
Since I've started to teach myself the Ruby dynamic programming language you can use this Ruby script to send yourself notification to Google Talk when a friend post a message to Twitter.
Steps:
1) Download Ruby
2) Install Ruby and setup a path to C:\Ruby\bin
3) Install the twitter gem: gem install twitter
4) Install the Jabber gem: gem install xmpp4r
5) Update the script by adding your Twitter username and password, Google Talk username (like lenniedg@gmail.com), password and notification address (like lenniedg@gmail.com)
6) run the script: ruby TwitterIMNotify_share.rb
I love Ruby! :)
Friday, March 6, 2009
Write a Share Trading Bot Challenge
Programming can also be fun :-)
David Bolton from C/C++/C# About.com started a challenge where you must write a bot in C, C++ or C# where the bot must do share trading.
Visit the challenge webpage for more information.
David Bolton from C/C++/C# About.com started a challenge where you must write a bot in C, C++ or C# where the bot must do share trading.
Visit the challenge webpage for more information.
Thursday, March 5, 2009
Weekly Source Code: PHP - Email Address Images
Sorry ladies & gents that there wasn't a weekly source code last week, work was crazy.
On beds.co.za which is one of the websites I'm working on, you will notice that the email address for an accommodation is actually an image and that there is in the HTML no "mailto:" tag. This is one way to prevent spammers from grabbing your email address from a website by converting the email address to an image and then use my No SPAM email link functionality (that I must still port over from .Net to PHP)
Here's the code that create the image
the email address get stored in $emailAddressEntity, for example "lenniedg@gmail.com"
@imagecreate is the PHP method that create the image.
After this you can refer to the image
Resources:
@imagecreate
On beds.co.za which is one of the websites I'm working on, you will notice that the email address for an accommodation is actually an image and that there is in the HTML no "mailto:" tag. This is one way to prevent spammers from grabbing your email address from a website by converting the email address to an image and then use my No SPAM email link functionality (that I must still port over from .Net to PHP)
Here's the code that create the image
the email address get stored in $emailAddressEntity, for example "lenniedg@gmail.com"
@imagecreate is the PHP method that create the image.
After this you can refer to the image
Resources:
@imagecreate
Saturday, February 14, 2009
Weekly Source Code: Create A Table With Hyperlinks In PHP
A friend is busy with a website and asked me how to create a table with hyperlinks using PHP/mySQL so in this Weekly Source Code edition I will explain just how.
First you need to connect to the database, for this you use the mysql_connect method, then you run your select SQL query and ouput the result in HTML.
See the sample code.
If you wish to open the result in a popup window then call a Javascript function from the anchor tag's onclick event, in the Javascript function you can open a window with window.open().
Please Note:
- I pass the record id to the updateuser.php page, this is so that the page know which user I wish to update.
- I refer to the record in the row via its field name, you can also refer via its record position in the result for example: $row[1] refer to "Firstname" field.
- This will display all the records in the table, you can add some paging to the table to only display like 10 records at a time.
- For basic PHP you output HTML this way where your PHP and HTML code get mixed, its generally a good idea to use a template framework like Smarty where application code is seperated from the presentation.
References:
PHP mySQL Functions
PHP Manual
First you need to connect to the database, for this you use the mysql_connect method, then you run your select SQL query and ouput the result in HTML.
See the sample code.
If you wish to open the result in a popup window then call a Javascript function from the anchor tag's onclick event, in the Javascript function you can open a window with window.open().
Please Note:
- I pass the record id to the updateuser.php page, this is so that the page know which user I wish to update.
- I refer to the record in the row via its field name, you can also refer via its record position in the result for example: $row[1] refer to "Firstname" field.
- This will display all the records in the table, you can add some paging to the table to only display like 10 records at a time.
- For basic PHP you output HTML this way where your PHP and HTML code get mixed, its generally a good idea to use a template framework like Smarty where application code is seperated from the presentation.
References:
PHP mySQL Functions
PHP Manual
Friday, February 13, 2009
Altair 8080 - Bill Gate's Altair BASIC
The Altair was the first computer released to the public in January 1975 (check here for history) by MITS, it was a very ugly machine that could only be coded in machine/assembly language by flipping switches. Basically saying: "Real Programmer's Don't Need Keyboards!"
Bill Gates & Paul Allen wrote Altair BASIC which was Microsoft's first product.
I downloaded the Altair emulator and stuggled to get it working but after awhile I finally got it working coding my first "Hello World!" in Altair BASIC!! This is so good to use the first computer and popular programming language.
How to use:
Bill Gates & Paul Allen wrote Altair BASIC which was Microsoft's first product.
I downloaded the Altair emulator and stuggled to get it working but after awhile I finally got it working coding my first "Hello World!" in Altair BASIC!! This is so good to use the first computer and popular programming language.
How to use:
- Run the Altair emulator.
- Load the disk with the Altair BASIC image.
- Toggle (that is on e.g. binary 1) all keys from A15 - A8, A7 to A0 must be down.
- Toggle EXAMINE
- Toggle down A15 - A8
- Toggle RUN
- A console window will open with the Altair BASIC running.
Subscribe to:
Posts (Atom)