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... Copy/Delete/Permission directory using System; using System.IO; using System.Security.AccessControl; namespace Bruce.Lib {     public class DirHelper     {         /// <...
Stats
Add assembly search path for program
app.config
  1. <configuration>
  2.     <runtime>
  3.         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  4.             <probing privatePath="assemblypath;works\assm;"/>
  5.         </assemblyBinding>
  6.     </runtime>
  7. </configuration>
Change the AppDomain's Base Directory and Environment Directory
  1. // Update AppDomain's Base Directory
  2. string root_path = "c:\\temp\\";
  3. AppDomain.CurrentDomain.SetData("APPBASE", root_path);
  4.  
  5. // Retrieve AppDomain's Base Directory
  6. AppDomain.CurrentDomain.BaseDirectory.ToString()
  7.  
  8. // Update Environment's Current Directory
  9. Environment.CurrentDirectory = root_path;
Dynamic load config file
  1. string strConfigPath = "your_config_file_path.config";
  2. ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
  3. fileMap.ExeConfigFilename = strConfigPath;
  4. DefaultConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
jQuery delegate
  1. <html>
  2. <head>
  3. <script type="text/javascript" src="jquery-1.7.1.min.js"></script>
  4. <script type="text/javascript">
  5.     $(function(){
  6.         // add row button
  7.         $('.append_button').click(function(){
  8.             var row = $('<div class="lister">'+new Date()+'&nbsp;&nbsp;&nbsp;<input type="button" class="row_button" value="click me!" /></div>');
  9.             row.appendTo('.container');
  10.         });
  11.         
  12.         // delegate for append button
  13.         $('.container').delegate('.lister input:button', 'click', function(){
  14.             alert('delegate ok!');
  15.         });
  16.         // delegate for append button (falied, because .lister was not found on delegate action)
  17.         $('.container .lister').delegate('input:button', 'click', function(){
  18.             alert('delegate, again!');
  19.         });
  20.     });
  21. </script>
  22. </head>
  23. <body>
  24. <div class="container">
  25.     <input type="button" class="append_button" value="Add" />
  26. </div>
  27. </body>
  28. </html>
DateTime format code
Style CodeStyleFormatExample
0 or 100Default. Equivalent to not specifying a style code.mon dd yyyy hh:mmAMSep 8 2007 9:00PM
1USA date.mm/dd/yy09/08/07
2ANSI date.yy.mm.dd07.09.08
3UK / French date.dd/mm/yy08/09/07
4German date.dd.mm.yy08.09.07
5Italian date.dd-mm-yy08-09-07
6Abbreviated month.dd mmm yy08 Sep 07
7Abbreviated month.mmm dd, yySep 08, 07
8 or 10824 hour time.HH:mm:ss21:00:00
9 or 109Default formatting with seconds and milliseconds appended.mon dd yyyy hh:mm:ss:fffAMSep 8 2007 9:00:00:000PM
10USA date with hyphen separators.mm-dd-yy09-08-07
11Japanese date.yy/mm/dd07/09/08
12ISO date.yymmdd070908
13 or 113European default with seconds and milliseconds.dd mon yyyy HH:mm:ss:fff08 Sep 2007 21:00:00:000
14 or 11424 hour time with milliseconds.HH:mm:ss:fff21:00:00:000
20 or 120ODBC canonical date and time.yyyy-mm-dd HH:mm:ss2007-09-08 21:00:00
21 or 121ODBC canonical date and time with milliseconds.yyyy-mm-dd HH:mm:ss.fff2007-09-08 21:00:00.000
101USA date with century.mm/dd/yyyy09/08/2007
102ANSI date with century.yyyy.mm.dd2007/09/08
103UK / French date with century.dd/mm/yyyy08/09/2007
104German date with century.dd.mm.yyyy08.09.2007
105Italian date with century.dd-mm-yyyy08-09-2007
106Abbreviated month with century.dd mmm yyyy08 Sep 2007
107Abbreviated month with century.mmm dd, yyyySep 08, 2007
110USA date with hyphen separators and century.mm-dd-yyyy09-08-2007
111Japanese date with century.yyyy/mm/dd2007/09/08
112ISO date with century.yymmdd20070908
126ISO8601, for use in XML.yyy-mm-ddThh:mm:ss2007-09-08T21:00:00
Diff Time
  1. DateTime from = new DateTime(2011, 1, 7);
  2. DateTime to = DateTime.Now;
  3. TimeSpan ts = to - from;
  4.  
  5. Console.WriteLine("start time : {0:yyyy/MM/dd HH:mm:ss}", from);
  6. Console.WriteLine("end time   : {0:yyyy/MM/dd HH:mm:ss}", to);
  7. Console.WriteLine("time diff  : {0}", ts);
  8. Console.WriteLine("month diff   : {0}", (to.Month - from.Month) + 12 * (to.Year - from.Year));
  9. Console.WriteLine("day diff     : {0}", ts.TotalDays);
  10. Console.WriteLine("hour difff   : {0}", ts.TotalHours);
  11. Console.WriteLine("minutes diff : {0}", ts.TotalMinutes);
  12. Console.WriteLine("second diff  : {0}", ts.TotalSeconds);