Skip to content

Instantly share code, notes, and snippets.

View akunzai's full-sized avatar

Charley Wu akunzai

  • Taipei,Taiwan
  • 23:19 (UTC +08:00)
  • X @akunzai
View GitHub Profile
@akunzai
akunzai / OrderedContractResolver.cs
Created January 8, 2014 07:39
OrderedContractResolver
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
public class OrderedContractResolver : DefaultContractResolver {
protected override System.Collections.Generic.IList<JsonProperty> CreateProperties(System.Type type, MemberSerialization memberSerialization) {
return base.CreateProperties(type, memberSerialization).OrderBy(p => p.PropertyName).ToList();
}
}
@akunzai
akunzai / UnixTimeType.cs
Last active March 25, 2018 14:53
NHibernate UnixTime UserType
using System;
using System.Data;
using NHibernate.SqlTypes;
using NHibernate.Util;
namespace NHibernate.UserTypes
{
public class UnixTimeType : IUserType
{
public System.Type ReturnedType => typeof(DateTimeOffset);
@akunzai
akunzai / HttpGet.java
Last active August 29, 2015 14:00
A simple Java class to provide functionality similar to Wget
import java.io.*;
import java.net.*;
public class JGet {
public static void main(String[] args) {
if ( (args.length == 0) ){
System.err.println( "\nUsage: java HttpGet [urlToGet]" );
System.exit(1);
}
String url = args[0];
@akunzai
akunzai / HttpGet.groovy
Last active August 29, 2015 14:05
A simple Groovy class to provide functionality similar to Wget
#!/usr/bin/env groovy
if (!this.args.length){
scriptName = getClass().protectionDomain.codeSource.location.path.split('/')[-1]
throw new RuntimeException( "Usage: groovy ${scriptName} [urlToGet]" )
}
println new URL(this.args[0]).text
@akunzai
akunzai / logback.xml
Last active August 29, 2015 14:05
logback xml configuration example
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds" debug="false">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<charset>utf-8</charset>
<pattern>%date [%thread] %-5level %logger{39} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--See also http://logback.qos.ch/manual/appenders.html#RollingFileAppender-->
@akunzai
akunzai / redis_mv.sh
Created November 19, 2014 08:05
move redis elements from db to another db (local)
#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage: $0 [src db] [dest db]"
exit 0
else
srcdb="$1"
fi
if [ "$2" == "" ]; then
destdb="1"
else
@akunzai
akunzai / ODataPageLinkBuilder.cs
Last active August 29, 2015 14:21
OData PageLink Header Builder
using System.Collections.Generic;
using System.Web.Http;
using System.Web.Http.Routing;
namespace System.Net.Http {
/// <summary>
/// OData PageLink Header Builder
/// </summary>
//http://www.jerriepelser.com/blog/paging-in-aspnet-webapi-pagination-links
public class ODataPageLinkBuilder {
@akunzai
akunzai / HttpRequestMessageExtensions.cs
Created June 23, 2015 14:11
Extends the HttpRequestMessage collection
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
namespace System.Web.Http {
/// <summary>
/// Extends the HttpRequestMessage collection
/// </summary>
/// <remarks>http://weblog.west-wind.com/posts/2013/Apr/15/WebAPI-Getting-Headers-QueryString-and-Cookie-Values</remarks>
public static class HttpRequestMessageExtensions {
@akunzai
akunzai / parseMsDateTime.js
Created July 8, 2015 02:56
Parse Microsoft Json DateFormat to Date
new Date(parseInt('/Date(1436323325308)/'.substr(6,13),10))
@akunzai
akunzai / HttpResponseExtensions.cs
Created June 11, 2016 15:00
clone Cookies from Response to Request
using System.Collections.Generic;
namespace System.Net.Http
{
public static class HttpResponseExtensions
{
/// <summary>
/// clone Cookies from Response to Request
/// </summary>
/// <param name="response"></param>