Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Get lastest record of workitem
SQL Server
  1. -- get lastest record of every instance
  2.  
  3. SELECT * FROM [HISTORY] H
  4. WHERE [CREATEDTIME]  = 
  5.     (
  6.         SELECT MAX([CREATEDTIME]) FROM [HISTORY] M 
  7.         WHERE M.[PROCESSINSTANCEID] = H.[PROCESSINSTANCEID] AND M.[EVENTTYPE] = H.[EVENTTYPE]
  8.     )
  9. ORDER BY [PROCESSINSTANCEID]
Extension method
  1. class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         Console.WriteLine(StringExtension.UrlEncodeMethod("中文"));
  6.         Console.WriteLine("中文".UrlEncode());
  7.         Console.Read();
  8.     }
  9. }
  10.  
  11.  
  12. static class StringExtension
  13. {
  14.     public static string UrlEncodeMethod(string s)
  15.     {
  16.         return HttpUtility.UrlEncode(s);
  17.     }
  18.  
  19.     public static string UrlEncode(this string s)
  20.     {
  21.         return HttpUtility.UrlEncode(s);
  22.     }
  23. }
Reference to container in actionlistener
  1. import java.awt.event.ActionEvent;
  2. import java.awt.event.ActionListener;
  3.  
  4. import javax.swing.JButton;
  5. import javax.swing.JFrame;
  6. import javax.swing.JOptionPane;
  7.  
  8. public class TestAction extends JFrame {
  9.  
  10.     public TestAction() {
  11.         this.setTitle("Test Click action");
  12.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13.         this.setSize(300, 300);
  14.         this.setLocation(200, 200);
  15.  
  16.         JButton button = new JButton("click me");
  17.         button.addActionListener(new ActionListener() {
  18.  
  19.             @Override
  20.             public void actionPerformed(ActionEvent e) {
  21.                 JOptionPane.showMessageDialog(TestAction.this, TestAction.this.getTitle());
  22.             }
  23.  
  24.         });
  25.         this.getContentPane().add(button);
  26.         this.setVisible(true);
  27.     }
  28.  
  29.     public static void main(String[] args) {
  30.         new TestAction();
  31.     }
  32. }
review : delegate in c#
I think I've got old because while using delegate, I couldn't remember it's usage. So I think it's a good idea to take a review and memo it here.
  1. using System;
  2. using System.ComponentModel;
  3. using System.ComponentModel.Design;
  4. using System.Collections;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Workflow.ComponentModel.Compiler;
  8. using System.Workflow.ComponentModel.Serialization;
  9. using System.Workflow.ComponentModel;
  10. using System.Workflow.ComponentModel.Design;
  11. using System.Workflow.Runtime;
  12. using System.Workflow.Activities;
  13. using System.Workflow.Activities.Rules;
  14.  
  15. namespace wfConsole
  16. {
  17.     delegate void PrintLine();
  18.     delegate void PrintContent(string s, int count);
  19.  
  20.     public sealed partial class Workflow1 : SequentialWorkflowActivity
  21.     {
  22.         public Workflow1()
  23.         {
  24.             InitializeComponent();
  25.         }
  26.  
  27.         private void ReviewDelegate_ExecuteCode(object sender, EventArgs e)
  28.         {
  29.             // 委派 C# 1.0
  30.             PrintLine pl = new PrintLine(this.WriteLine);
  31.             PrintContent pc = new PrintContent(this.WriteContent);
  32.             pl.Invoke();
  33.             pc.Invoke("C# 1.0", 5);
  34.  
  35.             // 委派 C# 2.0
  36.             PrintLine pl2 = delegate()
  37.             {
  38.                 Console.WriteLine("********************");
  39.             };
  40.             PrintContent pc2 = delegate(string s, int count)
  41.             {
  42.                 for (int i = 0; i < count; i++)
  43.                 {
  44.                     Console.Write("{0:00} ", i + 1);
  45.                     Console.WriteLine(s);
  46.                 }
  47.             };
  48.             pl2.Invoke();
  49.             pc2.Invoke("C# 2.0", 5);
  50.  
  51.             // 委派 C# 3.0
  52.             PrintLine pl3 = () =>
  53.             {
  54.                 Console.WriteLine("----------------------");
  55.             };
  56.             PrintContent pc3 = (string s, int count) =>
  57.             {
  58.                 for (int i = 0; i < count; i++)
  59.                 {
  60.                     Console.Write("{0:00} ", i + 1);
  61.                     Console.WriteLine(s);
  62.                 }
  63.             };
  64.             pl3.Invoke();
  65.             pc3.Invoke("C# 3.0", 5);
  66.  
  67.             Console.Read();
  68.         }
  69.  
  70.         private void WriteLine()
  71.         {
  72.             Console.WriteLine("=========================");
  73.         }
  74.  
  75.         private void WriteContent(string s, int count)
  76.         {
  77.             for (int i = 0; i < count; i++)
  78.             {
  79.                 Console.Write("{0:00} ", i + 1);
  80.                 Console.WriteLine(s);
  81.             }
  82.         }
  83.     }
  84.  
  85. }
Enable/disable network adapter
windows:
  1. netsh interface set interface <interface name> DISABLED
  2. netsh interface set interface <interface name> ENABLED
linux:
  1. ifconfig eth1 down
  2. ifconfig eth1 up
SVN Version control
Visual SVN
http://www.visualsvn.com/
TortoiseSVN 
http://tortoisesvn.net/
AnkhSVN 
http://ankhsvn.open.collab.net/

AnkhSVN で外部 diff

ツール >> AnkhSVN >> Edit the AnkhSVN configuration

DiffExePath
"C:\Program Files\WinMerge\WinMergeU.exe" -e -x -ub "%base" "%mine"
MergeExePath
"C:\Program Files\TortoiseSVN\bin\TortoiseMerge.exe" /base:"%base" /theirs:"%theirs" /mine:"%mine" /merged:"%merged"
refernect : http://d.hatena.ne.jp/MillyC/20071010/1192006340

backup/restore

從原有的Subversion (svn)備份出來,並還原到新的Subversion Server 上。

備份Subversion 的repository 並將備份檔傳到要還原的機器上。

1. svnadmin dump /path/to/project/ >/tmp/project.dump

2. scp -rp /tmp/project.dump user@192.168.1.1:/tmp/

還原

1. mkdir -p /path/to

2. svnadmin create /path/to/project

3. svnadmin load /path/to/project < /tmp/project.dump

4. chmod own.own /path/to/project -R
Shared memory (file base) in Java
  1. import java.io.File;
  2. import java.io.RandomAccessFile;
  3. import java.nio.MappedByteBuffer;
  4. import java.nio.channels.FileChannel;
  5. import java.nio.channels.FileChannel.MapMode;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Date;
  8.  
  9. public class SmWrite {
  10.  
  11.     public static void main(String[] args) throws Exception {
  12.         File file = new File("c:/mem.txt");
  13.         int length = (int) file.length();
  14.         String mode = "rw";
  15.         FileChannel fc = new RandomAccessFile(file, mode).getChannel();
  16.         MappedByteBuffer mbb = fc.map(MapMode.READ_WRITE, 0, length);
  17.         String format = "yyyy/MM/dd HH:mm:ss";
  18.         SimpleDateFormat sdf = new SimpleDateFormat(format);
  19.         while (true) {
  20.             String now = sdf.format(new Date());
  21.             byte[] b = now.getBytes();
  22.             mbb.rewind();
  23.             mbb.put(b, 0, b.length);
  24.             mbb.force();
  25.             Thread.sleep(1000);
  26.         }
  27.     }
  28. }
  1. import java.io.File;
  2. import java.io.RandomAccessFile;
  3. import java.nio.MappedByteBuffer;
  4. import java.nio.channels.FileChannel;
  5. import java.nio.channels.FileChannel.MapMode;
  6. import java.text.SimpleDateFormat;
  7.  
  8. public class SmRead {
  9.  
  10.     public static void main(String[] args) throws Exception {
  11.         File file = new File("c:/mem.txt");
  12.         int length = (int) file.length();
  13.         String mode = "rw";
  14.         FileChannel fc = new RandomAccessFile(file, mode).getChannel();
  15.         MappedByteBuffer mbb = fc.map(MapMode.READ_WRITE, 0, length);
  16.         String format = "yyyy/MM/dd HH:mm:ss";
  17.         SimpleDateFormat sdf = new SimpleDateFormat(format);
  18.         byte[] b = new byte[format.length()];
  19.         while (true) {
  20.             mbb.rewind();
  21.             mbb.get(b, 0, b.length);
  22.             String now = new String(b);
  23.             System.out.println(now);
  24.             Thread.sleep(1000);
  25.         }
  26.     }
  27. }
reference : http://www.javaworld.com.tw/jute/post/view?bid=29&id=273887
Try catch in SQL Server 2005
  1. BEGIN
  2.     BEGIN TRANSACTION 
  3.     BEGIN TRY
  4.         // QUERY HERE
  5.     END TRY
  6.     BEGIN CATCH
  7.         PRINT ERROR_MESSAGE();
  8.         ROLLBACK
  9.     END CATCH
  10. END
.net closure
  1. Thread t = new Thread(() =>
  2.     {
  3.         while (true)
  4.         {
  5.             Console.WriteLine(DateTime.Now);
  6.             Thread.Sleep(1000);
  7.         }
  8.     }
  9. );
  10.  
  11. t.Start();
reference : http://diditwith.net/2007/02/09/WhatsInAClosure.aspx
i.e. CSS expression
  1. <html>
  2. <style>
  3. {
  4. border:1px solid red;
  5. max-width:30em;
  6. width:expression( 
  7.     document.body.clientWidth > (500/12) * 
  8.     parseInt(document.body.currentStyle.fontSize)?
  9.         "30em":
  10.         "auto" );
  11. }
  12. </style>
  13. <body>
  14. <p>
  15. [alot of text]
  16. </p>
  17. </body>
  18. </html>
reference : http://www.svendtofte.com/code/max_width_in_ie/