RSS Feed for ProgrammingCategory: Programming

Teaching Kids to Program–Resources »

Resources to get your kids started on programming Scratch helps young people learn to think creatively, reason systematically, and work collaboratively — essential skills for life in the 21st century. Scratch is a project of the Lifelong Kindergarten Group at the MIT Media Lab. It is provided free of charge. Alice is an innovative 3D [...]

Java–Sort a Map by Values »

Here is a generic method to sort a Map by its values 1: /** 2: * Sort a map by values 3: * 4: * @param map Unsorted map 5: * @return Sorted map 6: */ 7: public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { 8: List<Map.Entry<K, V>> list [...]

AT Commands for Android Phone »

Here is an example of using MessagingToolkit to send AT commands to Android phone. The Android phone used here is a LG Optimus One P500. Before you can send AT commands, make sure you have the driver installed for you phone. For LG phone, you can use LG Mobile Support Tool. After the driver is [...]

.NET: DateTime from Milliseconds »

In Java, for Date we can use milliseconds to get the Date object, e.g. new Date(long milliseconds). In .NET, there is a similar constructor, but it is accepting the number of ticks, which is new DateTime(long ticks). In .NET, if you want to construct a DateTime object from number of milliseconds since January 1, 1970, [...]

Protocol Buffers »

Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. You write a .proto file like this: message Person {  required int32 id = 1;  required string name = 2;  optional string email = 3;} [...]

SubSonic SELECT IN and BETWEEN »

For the SQL “select … from table where value in (v1, v2)”, in SubSonic you need to use the SqlQuery statement 1: // numbers is a List<string> 2: SqlQuery query = new Select().From("Pick44D").Where(Pick44DTable.MatchedNoColumn).In(numbers).OrderDesc(new string[] { "DrawDate" }); 3: List<Pick44D> result = query.ExecuteTypedList<Pick44D>(); To add the BETWEEN clause 1: // SqlDateFormat = yyyy-MM-dd 2: SqlQuery query [...]

SubSonic SQLite Data Mappings »

int maps to Int32 integer maps to Int64 bit maps to boolean guid maps to Guid long maps to Int64 For the complete listing, please see below code snippet from SubSonic 1: switch(sqlType) 2: { 3: case "varchar": 4: return DbType.AnsiString; 5: 6: case "nvarchar": 7: return DbType.String; 8: 9: case "int": 10: return DbType.Int32; [...]

SubSonic: Select Distinct Column Values »

To do a select distinct from a column for a database table using SubSonic, it is very straightforward Below is the code to get the unique customer number from the Customer table, and order them in descending order 1: Customer.All().Select(c => c.CustomerNo).Distinct().OrderByDescending(c => c) .

C# UserControl: Detect Design Mode »

When developing a user control in .NET, if certain codes are not meant to be run in design mode, then you should check for it and avoid executing those code 1: /// <summary> 2: /// Handles the Load event of the MenuPanel control. 3: /// </summary> 4: /// <param name="sender">The source of the event.</param> 5: [...]

Windows: Generate WMI Code »

The WMI Code Creator tool allows you to generate VBScript, C#, and VB .NET code that uses WMI to complete a management task such as querying for management data, executing a method from a WMI class, or receiving event notifications using WMI. The WMI Code Creator tool generates code that uses WMI to obtain management [...]

.NET: Convert to Local Timezone »

You can use the style DateTimeStyles.AssumeLocal to parse the date time string if there is no timezone information contained in the string. E.g. 1: DateTime.ParseExact(dateString, DateFormats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal); If datestring contains no time zone information, the DateTime..::.Parse(String, IFormatProvider, DateTimeStyles) method returns a DateTime value whose Kind property is DateTimeKind..::.Unspecified unless a styles flag indicates otherwise. [...]

Oracle BPEL: Partner Link Timeout »

Starting version 10.1.3.4, to set time out in seconds for a partner link, it is just configuration in bpel.xml. E.g. the configuration below sets the timeout to 5 seconds 1: <partnerLinkBinding name="WebService">  2:   <property name="timeout">5</property>   3: <property name="optSoapShortcut">false</property>    4: <!– other PartnerLink properties –> 5: </partnerLinkBinding> If  the WebService is on the SAME host as [...]

Oracle BPEL: Adding CDATA Section to XML Payload »

In Oracle BPEL, to add a CDATA section to a XML payload looks like not easy. E.g. if you want to add the CDATA to the XML below, it is not easy as using Java 1: <?xml version = ’1.0′ encoding = ‘UTF-8′?> 2: <tns:RunTask><xmlRequestDocument><![CDATA[test 3: data]]></xmlRequestDocument></tns:RunTask> As of version 10.1.3.5, the ora:toCDATA() is introduced [...]

C#: Convert Byte to SByte »

Here is a simple way to convert SByte to Byte in C#. E.g. if you want to convert the value of 129 from data type Byte to –127 in SByte 1: byte byteValue = 129; 2: sbyte sb = unchecked((sbyte)byteValue); 3: Console.WriteLine(sb);

Viewing Outlook Msg File OLE Type Attachment »

This is a bit tricky to view OLE type of attachment in Outlook .msg file. You need to use MsWord library in order to extract the attachment. Here is the code snippet that does the trick. 1: for(int loop = 1 ; loop < (mItem.Attachments.Count+1) ; loop++){ 2: attachment = mItem.Attachments[loop]; 3: if(attachment.Type == Outlook.OlAttachmentType.olOLE){ [...]

Facebook SDK from Microsoft »

The Facebook toolkit is provided as a Facebook Client Library similar to Facebook’s PHP Client Library or Facebook’s JavaScript library. The goal is to enable .NET developers to quickly and easily leverage the various features of the Facebook Platform. This toolkit has evolved over time with input from the community and from Microsoft. The latest [...]

Asynchronous Web Service using WS-Addressing »

WS-Addressing provides way to specify message addressing information independent of transport layer. WS-Addressing provides a way to specify delivery, reply-to, and fault-handler addressing information in a SOAP envelope. WS-Addressing can be used in conjunction with other specifications such as WS-Security to authenticate and WS-Policy to define policies for the service. WS-Addressing has two key constructs [...]

Go – A New Systems Programming Language »

Go is a new systems programming language from Google. The goal of the project, as quoted below No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously. There are several trends: Computers are enormously quicker but software development is not faster. Dependency management is a [...]

Java: Time Synchronization Trick in Programming »

In previous article, I have written about Java Time Sync Problem. JVM time follows the CPU ticks once it is started even though the application servers are time synced with NTP. With this in mind, if developer does not use a centralized server to retrieve the time, it would pose a problem. Image the following [...]

Java: Detect and Use System Proxy »

Here is a Java class that you use to detect and use the system proxy, or direct connection is available to the Internet. Basically, it uses java.net.useSystemProxies property which is available starting JDK 5. 1: package com.cdp.proxy.plugins; 2:  3:  4: import java.net.InetSocketAddress; 5: import java.net.Proxy; 6: import java.net.ProxySelector; 7: import java.net.SocketAddress; 8: import java.util.List; 9:  [...]