Skip to content

Instantly share code, notes, and snippets.

View larrynung's full-sized avatar

larrynung larrynung

View GitHub Profile
@larrynung
larrynung / Contract.ts
Created April 3, 2018 07:03 — forked from fdecampredon/Contract.ts
Contract programming with typescript and decorators
@In((a: string, b: string) => {
assert(typeof a === 'string');
assert(typeof b === 'string');
assert(a.length > 5);
assert(a.length > 7);
})
@Out((result: string) => {
assert(typeof result === 'string');
assert(a.length > 12);
})
@larrynung
larrynung / gist:6658619
Last active December 23, 2015 15:58
regionerate layout
<?xml version="1.0" encoding="utf-8"?>
<!-- This is the default code layout which will be applied if you choose "Use the default Code Layout which that ships with Regionerate". Notice that modifying this file will not affect Regionerate. You can modify this file and load it manualy by choosing "Use custom" under "Primary Code Layout", or you can place it in the "My Code Layouts" directory. -->
<CodeLayout xmlns="http://regionerate.net/schemas/0.7.3.0/CodeLayout.xsd">
<ForEach Type="Struct">
<CreateRegion Title="Nested Classes" PadFirstChild="0" PadLastChild="0">
<PutNestedClasses>
<OrderBy>
<Name />
</OrderBy>
</PutNestedClasses>
@larrynung
larrynung / gist:6519765
Created September 11, 2013 05:50
DoTest Function... Easy to test process's elapsed time...
private static long DoTest(int count, Action action)
{
var sw = Stopwatch.StartNew();
for (int i = 0; i < count; ++i)
{
action();
}
return sw.ElapsedMilliseconds;
}
@larrynung
larrynung / gist:6518958
Created September 11, 2013 03:17
Fix and refactoring GetUniqueKey() method Reference:Generating Unique Keys in .Net (http://www.codeproject.com/Articles/14403/Generating-Unique-Keys-in-Net)
private static string GetUniqueKey()
{
return GetUniqueKey(8);
}
private static string GetUniqueKey(int size)
{
var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
@larrynung
larrynung / gist:6131131
Created August 1, 2013 13:05
GAE's Python Datastore API
from google.appengine.ext import db
import webapp2
import uuid
class Article(db.Model):
id = db.StringProperty(required=True)
name = db.StringProperty()
content = db.TextProperty()
class Blog(db.Model):
@larrynung
larrynung / gist:6130083
Created August 1, 2013 10:04
GAE's Users Service Demo
from google.appengine.api import users
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
self.response.write(
"""
@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")
<html>
<input x-webkit-speech>
</body>
</html>
@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
};
@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)