Archive

Archive for the ‘Programming’ Category

WP-Syntax in WordPress

July 16th, 2010

(link to original post: http://wordpress.org/extend/plugins/wp-syntax/other_notes/)

Usage

Wrap code blocks with <pre lang="LANGUAGE" line="1"> and </pre> where LANGUAGE is a GeSHi supported language syntax. See below for a full list of supported languages. The line attribute is optional.

Example 1: PHP, no line numbers

<pre lang="php">
<div id="foo">
<?php
  function foo() {
    echo "Hello World!\\n";
  }
?>
</div>
</pre>

Example 2: Java, with line numbers

<pre lang="java" line="1">
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello World!");
  }
}
</pre>

Example 3: Ruby, with line numbers starting at 18

<pre lang="ruby" line="18">
class Example
  def example(arg1)
    return "Hello: " + arg1.to_s
  end
end
</pre>

Example 4: If your code already has html entities escaped, use escaped="true" as an option

<pre lang="xml" escaped="true">
&lt;xml&gt;Hello&lt;/xml&gt;
</pre>

Supported Languages

The following languages are supported in the lang attribute:

abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, avisynth, bash, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cil, cfdg, cfm, cmake, cobol, cpp-qt, cpp, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, bnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, pic16, pixelbender, perl, php-brief, php, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, z80

(Bold languages just highlight the more popular ones.)

Styling Guidelines

WP-Syntax colors code using the default GeSHi colors. It also uses inline styling to make sure that code highlights still work in RSS feeds. It uses a default wp-syntax.css stylesheet for basic layout. To customize your styling, copy the default wp-content/plugins/wp-syntax/wp-syntax.css to your theme’s template directory and modify it. If a file named wp-syntax.css exists in your theme’s template directory, this stylesheet is used instead of the default. This allows theme authors to add their own customizations as they see fit.

Advanced Customization

WP-Syntax supports a wp_syntax_init_geshi action hook to customize GeSHi initialization settings. Blog owners can handle the hook in a hand-made plugin or somewhere else like this:

<?php
add_action('wp_syntax_init_geshi', 'my_custom_geshi_styles');

function my_custom_geshi_styles(&$geshi)
{
    $geshi->set_brackets_style('color: #000;');
    $geshi->set_keyword_group_style(1, 'color: #22f;');
}
?>

This allows for a great possibility of different customizations. Be sure to review the GeSHi Documentation.

Author: SquallLTT Categories: Programming Tags:

Some notes for handling string

July 16th, 2010

Clearing my phone since it is very messy with a lot of files, and found some notes here:

Handling string in C#
List of Numeric Formats

* C or C – For Currency. Uses the cultures currency symbol.
* D or D – Integer types. Add a number for 0 padding eg D5.
* E or e – Scientific notation.
* F or f – Fixed Point.
* G or g – Compact fixed-point/scientific notation.
* N or n – Number. This can be enhanced by a NumberFormatInfo object.
* P or p – Percentage.
* R or r – Round-trip. Keeps exact digits when converted to string and back.
* X or x – Hexadecimal. x – uses abcdef, X use ABCDEF.

Dates can also be specified either using Standard Format strings

* O or o – YYYY-MM-dd:mm:ss:ffffffffzz
* R or r – RFC1123 eg ddd, dd MMM yyyy HH:ss GMT
* s – sortable . yyyy-MM-ddTHH:mm:ss
* u – Universal Sort Date – yyyy-MM-dd HH:mm:ssZ

or Format specifiers. There are too many of those to list here. Example:

using System;
using System.Text;
using System.Globalization;
 
namespace ex6
{
    class Program
    {
        static void Main(string[] args)
        {
            // Numeric Formatting Examples
            // integer
            int i = 5678;
            string s = string.Format("{0,10:D}", i);  // Into a string right aligned 10 width
            Console.WriteLine("{0,10:D}", i);         // or output direct    
            Console.WriteLine("{0,10:D7}", i);         // or output direct with leading 0
 
            // double and currency in various formats
            double d=47.5;
            double bigd = 19876543.6754;
            Console.WriteLine("{0,15:C2}", d);  //  In Uk = £47.50 right aligned in 15 width
 
            Console.WriteLine("{0,15:N10}", bigd); //  Number 
            Console.WriteLine("{0,15:E3}", d);  //  Scientific 4.750E+001
            Console.WriteLine("{0,15:F5}", d);  //  Fixed Point 47.50000
            Console.WriteLine("{0,15:G4}", d);  //  Compact 47.5
            Console.WriteLine("{0,10:P2}", d/100.0);  //  %
            Console.WriteLine("{0,15:R}", bigd); //  Roundtrip - not a digit lost
 
            // Hex-a-diddly-decimal
            Console.WriteLine("{0,10:x8}", i);   // lowercase 0000162e
            Console.WriteLine("{0,10:X8}", i);   // uppercase 0000162E
 
 
            // Date formats
            DateTime dt = DateTime.Now;
            // Standards
            Console.WriteLine("{0:O}", dt);   // O or o  yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffzz
            Console.WriteLine("{0:R}", dt);   // R or r ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
            Console.WriteLine("{0:s}", dt);   // s yyyy'-'MM'-'dd'T'HH':'mm':'ss
            Console.WriteLine("{0:u}", dt);   // u yyyy'-'MM'-'dd HH':'mm':'ss'Z'
 
            // Using date/time specifiers
            Console.WriteLine("{0:t}", dt);  // short time
            Console.WriteLine("{0:T}", dt);  // long time
            Console.WriteLine("{0:d}", dt);  // short date 
            Console.WriteLine("{0:D}", dt);  // long date 
            Console.WriteLine("{0:f}", dt);  // long date / short time 
            Console.WriteLine("{0:F}", dt);  // long date / long time
            Console.WriteLine("{0:g}", dt);  // short date / short time 
            Console.WriteLine("{0:G}", dt);  // short date / long time
            Console.WriteLine("{0:o}", dt);  // Round Trip
 
            // roll your own... 
            Console.WriteLine("{0:dd/mm/yyyy HH:MM:ss}", dt);  // custom - what most people use (UK)!
            Console.WriteLine("{0:mm/dd/yyyy HH:MM:ss}", dt);  // custom - what most people use (US)!
            Console.WriteLine("{0:yyyy/mm/dd HH:MM:ss}", dt);  // custom - (Japan) Good for sorting!
 
            Console.WriteLine("{0:dd MMM yyyy HH:MM:ss}", dt);  // custom - month (UK)
            Console.WriteLine("{0:MMM dd yyyy HH:MM:ss}", dt);  // custom - month (US)
            Console.WriteLine("{0:yyyy MMM dd HH:MM:ss}", dt);  // custom - (Japan) 
            Console.ReadKey();
        }
    }
}

C:
Standard: \r\n
(don’t use \n\r)

Author: SquallLTT Categories: Programming Tags:

SquallLTT presents: My PDA phone :D

June 24th, 2009

Here is the link to the video clip: http://www.25phut.net/uploadedvideoclips/viva.html

In conclusion I’d like to say that Windows Mobile phones are the best, at least, to me. Countless softwares are available out there. And, I can do some coding for my PDA as u can see in the video, I’ve implemented image processing (Canny Edge detection), written a program to operate a robot via WIFI, and much more… :D

Network programming in C#

May 5th, 2009

Basic definitions

It is important to have a firm understanding about networking. Here, I only mention about some very basic knowledge.

- Protocol: is a set of rules and procedures used for communication. Computers on a network must agree upon a common protocol in order to communicate.

- IP (Internet Protocol) is the method or protocol by which data is sent from one device to another on the Internet. Each computer on the Internet has at least one IP address that uniquely identifies it from all other computers on the Internet. IP by itself is something like the postal system. It allows you to address a package and drop it in the system, but there is no direct link between you and the recipient. Though there are other network protocols available to the Windows network programmer, IP provides the most robust technique for sending data between network devices, especially if they are located across the Internet.

Read more…

Author: SquallLTT Categories: Programming Tags: , ,

C# programming language

May 5th, 2009

Microsoft .NET

Microsoft .NET contains 2 main components: Framework and Integrated Development Environment (IDE). Framework is the most important part of .NET and it is the core of the environment.

.NET Framework contains:

  • 4 main programming languages: C#, VB.NET, C++ and JScript.NET
  • Common Language Runtime (CLR) – this is the core of the framework – which is Microsoft implementation of the Common Language Infrastructure (CLI) standard – handles code execution and all of the tasks associated with it: compilation, memory management, security, thread management, and enforcement of type safety and use.

Read more…

Author: SquallLTT Categories: Programming Tags:

[VB.NET] Detect whether the USB device is plugged in or taken out without timer

May 3rd, 2009


.NET programming
The following VB.NET code will help you to check whether a USB device is plugged in or taken out. No timer is used here. You can integrate this tip to your program just by copy and paste.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
    Private WM_DEVICECHANGE As Integer = &amp;H219
 
    Public Enum WM_DEVICECHANGE_WPPARAMS As Integer
        DBT_CONFIGCHANGECANCELED = &amp;H19
        DBT_CONFIGCHANGED = &amp;H18
        DBT_CUSTOMEVENT = &amp;H8006
        DBT_DEVICEARRIVAL = &amp;H8000
        DBT_DEVICEQUERYREMOVE = &amp;H8001
        DBT_DEVICEQUERYREMOVEFAILED = &amp;H8002
        DBT_DEVICEREMOVECOMPLETE = &amp;H8004
        DBT_DEVICEREMOVEPENDING = &amp;H8003
        DBT_DEVICETYPESPECIFIC = &amp;H8005
        DBT_DEVNODES_CHANGED = &amp;H7
        DBT_QUERYCHANGECONFIG = &amp;H17
        DBT_USERDEFINED = &amp;HFFFF
    End Enum
 
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = WM_DEVICECHANGE Then
            Select Case m.WParam
                Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEARRIVAL
                    MsgBox("USB device is just plugged in!")
                Case WM_DEVICECHANGE_WPPARAMS.DBT_DEVICEREMOVECOMPLETE
                    MsgBox("USB device is just taken out")
            End Select
        End If
        MyBase.WndProc(m)
    End Sub
Author: SquallLTT Categories: Programming Tags: ,