Skip to content

Instantly share code, notes, and snippets.

View larrynung's full-sized avatar

larrynung larrynung

View GitHub Profile
@larrynung
larrynung / gist:5453283
Last active December 16, 2015 15:08
How metro app use WebAuthenticationBroker to do oauth
...
var result = await WebAuth(navigationUrl, redirectUrl);
if(result.ResponseStatus != WebAuthenticationStatus.Success)
return;
var response = result.ResponseData;
...
@larrynung
larrynung / gist:5507378
Last active December 16, 2015 22:29
Microsoft sync framework demo1
class Program
{
public static void Main(string[] args)
{
string path1 = args[0];
string path2 = args[1];
SyncFile(path1, path2, null, FileSyncOptions.None);
}
@larrynung
larrynung / gist:5509011
Last active December 16, 2015 22:39
CA1810 demo1
class Program
{
static void Main(string[] args)
{
Thread.Sleep(1000);
Console.WriteLine(DateTime.Now.ToString());
Console.WriteLine(Class1.TimeStamp.ToString());
Thread.Sleep(1000);
@larrynung
larrynung / gist:5509043
Created May 3, 2013 13:12
CA1810 demo1's MSIL code
.namespace ConsoleApplication43
{
.class private auto ansi beforefieldinit ConsoleApplication43.Class1
extends [mscorlib]System.Object
{
// Fields
.field public static valuetype [mscorlib]System.DateTime TimeStamp
// Methods
.method public hidebysig specialname rtspecialname
@larrynung
larrynung / Program.cs
Created May 4, 2013 14:49
beforefieldinit & precise 's performance test
class Program
{
static void Main(string[] args)
{
var count = 1000000000;
Console.WriteLine(DoTest(count, () =>
{
var timestamp = Class1.TimeStamp;
}).ToString());
@larrynung
larrynung / andortest.py
Created May 19, 2013 02:07
Python's and-or operation
print "'a' and 'b': ", 'a' and 'b'
print "'' and 'b': ", '' and 'b'
print "'a' and '': ", 'a' and ''
print "'a' and 'b' and 'c': ", 'a' and 'b' and 'c'
print ""
print "'a' or 'b': ", 'a' or 'b'
print "'' or 'b': ", '' or 'b'
print "'a' or '': ", 'a' or ''
@larrynung
larrynung / gist:5697828
Last active December 18, 2015 00:38
.NET 4.0 System.Runtime.Caching demo
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Caching;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
@larrynung
larrynung / gist:5703069
Last active December 18, 2015 01:19
How to use DropNet to get the contents in dropbox http://www.dotblogs.com.tw/larrynung/archive/2012/08/12/73985.aspx
...
private void btnLogin_Click(object sender, EventArgs e)
{
if (!String.IsNullOrEmpty(Properties.Settings.Default.SECRET) && !String.IsNullOrEmpty(Properties.Settings.Default.TOKEN))
{
m_DropNetClient.UserLogin = new UserLogin()
{
Secret = Properties.Settings.Default.SECRET,
Token = Properties.Settings.Default.TOKEN
};
<html>
<input x-webkit-speech>
</body>
</html>
@larrynung
larrynung / gist:6130066
Created August 1, 2013 10:01
GAE's Mail Python API demo
from google.appengine.api import users
from google.appengine.api import mail
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
sender = self.request.get("sender")
receiver = self.request.get("receiver")
subject = self.request.get("subject")
message = self.request.get("message")