Category: Programming
By admin on Sep 20, 2009 in .NET, freebies, personal, Programming | 0 Comments
I just released the community edition of MessagingToolkit messagingtoolkit is a .NET C# messaging library that can be used to send and receive messages using any ETSI 07.05 compliant GSM modem or phone handset connected to the PC serial port through serial cable, infrared or bluetooth. Some of the features of the library Send SMS [...]
By admin on Sep 4, 2009 in freebies, Programming | 1 Comment
CHESS is a tool for finding and reproducing Heisenbugs in concurrent programs. CHESS repeatedly runs a concurrent test ensuring that every run takes a different interleaving. If an interleaving results in an error, CHESS can reproduce the interleaving for improved debugging. CHESS is available for both managed and native programs.
By admin on Jul 7, 2009 in Java, Programming | 2 Comments
Predicate in Commons Collection is very useful for logic evaluation. The available predicates should fulfills most of your logic requirements, or you can even write your own custom predicate. AllPredicate AndPredicate AnyPredicate EqualPredicate ExceptionPredicate FalsePredicate IdentityPredicate InstanceofPredicate NonePredicate NotNullPredicate NotPredicate NullIsExceptionPredicate NullIsFalsePredicate NullIsTruePredicate NullPredicate OnePredicate OrPredicate TransformedPredicate TransformerPredicate, TruePredicate UniquePredicate You can combine predicates together [...]
By admin on Jun 29, 2009 in .NET, Programming | 0 Comments
In .NET, it is easy to retrieve all existing COM ports and sort them accordingly string[] portNames = SerialPort.GetPortNames(); var sortedList = portNames.OrderBy(port => Convert.ToInt32(port.Replace(“COM”, string.Empty))); foreach (string port in sortedList) { Console.WriteLine(port); }
By admin on Mar 24, 2009 in Java, Programming | 0 Comments
When this happened, and you are sure that the connection pool is actually enough to handle all the transactions, then most probably that there is a connection leakage lying within your application. E.g. the connection is not closed properly. One example in iBATIS is that you start a transaction, but does not end it. sqlMapClient.startTransaction(); [...]
By admin on Mar 15, 2009 in .NET, Programming | 0 Comments
Here is a simple way to detect if your content is ASCII or Unicode public void CheckForEncoding(string content) { int i = 0; for (i = 1; i <= content.Length; i++) { int code = Convert.ToInt32(Convert.ToChar(content.Substring(i – 1, 1))) ; if (code < 0 || code > 255) { Console.WriteLine(“Unicode”); return; } } Console.WriteLine(“ascii”); }
By admin on Feb 17, 2009 in Java, Oracle, Programming | 0 Comments
There are times that you may want to alter Oracle session information. If you are using iBATIS, this can be done the following way Create the update statement. E.g. <?xml version=”1.0″ encoding=”UTF-8″ ?> <!DOCTYPE sqlMap PUBLIC “-//ibatis.apache.org//DTD SQL Map 2.0//EN” “http://ibatis.apache.org/dtd/sql-map-2.dtd” > <sqlMap namespace=”TEST”> <update id=”update_sort_area_size” parameterClass=”int”> alter session set sort_area_size=#value# </update> <update id=”update_sort_area_retained_size” [...]
By admin on Feb 14, 2009 in .NET, Programming | 0 Comments
Normally you cannot use string in enum. However you can bypass using a trick, as shown below. /// <summary> /// Response expected from the gateway /// </summary> public enum Response { /// <summary> /// No respons expected, just return the result /// </summary> [StringValue("NONE")] None, /// <summary> /// Error response /// </summary> [StringValue("ERROR")] Error, /// [...]
By admin on Feb 9, 2009 in Java, Programming | 1 Comment
Performance tuning for embedded system is quite different from conventional programming Avoid Creating Objects Use Native Methods Prefer Virtual Over Interface Prefer Static Over Virtual Avoid Internal Getters/Setters Cache Field Lookups Declare Constants Final Use Enhanced For Loop Syntax With Caution Avoid Enums Use Package Scope with Inner Classes Avoid Float Some Sample Performance Numbers [...]
By admin on Feb 2, 2009 in .NET, Programming | 0 Comments
This is a dynamic way of creating different object factory for different types of gateway, which I used to connect to different kinds of servers. This is the interface, IGatewayFactory using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MessageGateway.Core.Base { /// <summary> /// Gateway factory interface /// </summary> /// <typeparam name=”T”>Derived gateway factory</typeparam> [...]
By admin on Jan 19, 2009 in Programming | 1 Comment
Make Fewer HTTP Requests Use a Content Delivery Network Add an Expires or a Cache-Control Header Gzip Components Put Stylesheets at the Top Put Scripts at the Bottom Avoid CSS Expressions Make JavaScript and CSS External Reduce DNS Lookups Minify JavaScript and CSS Avoid Redirects Remove Duplicate Scripts Configure ETags Make Ajax Cacheable Flush the [...]
By admin on Jan 15, 2009 in Java, Programming | 1 Comment
Logging is necessary for troubleshooting purpose but excessive logging impacts performance. In most application, if you need high performance, you have to reduce the amount of logging. If logging cannot be avoided, then you should try to output as much information as possible during a single logging operation, instead of logging multiple times consecutively. E.g., [...]
By admin on Jan 15, 2009 in Java, Programming | 0 Comments
I have a common class which is used to create the SqlMapClient object to access the database. The class is used by multiple Java processes. The problem is that I want each Java process to have specific database settings, and I do not want to maintain redundant information in different SQL mapping configuration files, e.g. [...]
By admin on Jan 7, 2009 in Java, Programming | 0 Comments
REST The Representational State Transfer (REST) is a web architectural style presented by Roy Fielding back in 2000 in his doctoral thesis. The basic idea of REST is the full exploitation of the HTTP protocol, in particular:It focuses on Resources, that is, each service should be designed as an action on a resource. It takes [...]
By admin on Dec 23, 2008 in Java, Programming | 2 Comments
This is what I have observed when I was putting some logging code in my Java application. The performance when I was using Commons Logging with Log4j is much slower than I was using Log4j alone. This is strange as I was expecting Commons Logging as just a thin wrapper around Log4j.
By admin on Dec 7, 2008 in open source, Programming | 0 Comments
haXe (pronounced as hex) is an open source programming language. While most of the other languages are bound to their own platform (Java to the JVM, C# to .Net, ActionScript to the Flash Player), haXe is a multiplatform language. It means that you can use haXe to target the following platforms : Javascript : You [...]
By admin on Nov 22, 2008 in Programming, side note | 0 Comments
This is a summary from the Pragmatic Programmer book. Care About Your CraftWhy spend your life developing software unless you care about doing it well? Think! About Your WorkTurn off the autopilot and take control. Constantly critique and appraise your work. Provide Options, Don’t Make Lame ExcusesInstead of excuses, provide options. Don’t say it can’t [...]
By admin on Nov 17, 2008 in general, Java, Programming | 0 Comments
These are the programming books that I read or am reading for year 2008, which I think is good for reading by developers. December is a long holiday. Any recommendations for good books for year 2008 which worth reading, irregardless of programming languages? Effective Java (2nd Edition) by Joshua Bloch Java Power Tools by John [...]
By admin on Nov 9, 2008 in Java, Programming | 0 Comments
ServiceLoader is a class available in earlier version of Java and staring JDK 6, it is available formally under java.util package. In JDK 6 – java.util.ServiceLoader Prior to JDK 6 – Refer to the document at http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific [...]
By admin on Oct 30, 2008 in Java, Programming | 0 Comments
Download the code here One thing good about object oriented language is that now we can reduce the conditional statements typically found in procedural language, which in turn can make our code more maintainable. In Java, normally if we want to refactor a long conditional statements, we use polymorphism, which results in a lot of [...]