Skip to content

Instantly share code, notes, and snippets.

View benloong's full-sized avatar

benloong benloong

View GitHub Profile
@benloong
benloong / functionperformance.cpp
Created December 20, 2013 03:51
c++11 direct function call, virtual function call, functor and std::function(using a lambda) performance test
#include <iostream>
#include <chrono>
#include <memory>
#include <functional>
using namespace std;
using namespace std::chrono;
class Base
{
@benloong
benloong / WebAssetHolder.cs
Created March 9, 2014 05:06
unity web asset management
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
public class WebAssetHolder : MonoBehaviour {
public class WebItem {
// C++11 32bit FNV-1 and FNV-1a string hasing (Fowler–Noll–Vo hash)
//
// Requires a compiler with C++11 support
// See main(...) for examples
#include <iostream>
#include <cassert>
namespace hash
{
@benloong
benloong / pack_array.hpp
Created March 18, 2014 09:26
c++11 meta sequence
template<typename T, T... _Rest>
struct array_pack;
template<typename T>
struct array_pack<T>{};
template<typename T, T _This, T... _Rest>
struct array_pack<T, _This, _Rest...> : private array_pack<T, _Rest...>
{
const T & operator[](const int pos)
{
//as cpp memory layout, indexing reversely
public static int getVersionCode(Context ctx) {
int versionCode = 0;
try {
PackageInfo pInfo = ctx.getPackageManager().getPackageInfo(
ctx.getPackageName(), 0);
versionCode = pInfo.versionCode;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
@benloong
benloong / ignoreFile
Created January 16, 2015 01:38
A better Unity Git Ignore File
[Ll]ibrary/
[Tt]emp/
[Oo]bj/
[Bb]uild/
[Dd]ebug/
[Rr]elease/
# Autogenerated VS/MD solution and project files
*.csproj
*.unityproj
@benloong
benloong / utf8.cs
Created August 14, 2015 05:27
utf-8编码规则, 可用于网络协议头的长度编码中。
public class UTF8
{
/// <summary>
/// 计算utf-8编码后的字节数
/// </summary>
/// <param name="code">Unicode</param>
/// <returns>utf-8编码后的字节数</returns>
public static int GetByteCount(int code)
{
@benloong
benloong / ReimportUnityEngineUI.cs
Created January 11, 2016 06:15
解决Unity UI timestamp guid不同步
using UnityEngine;
using UnityEditor;
using System.IO;
public class ReimportUnityEngineUI
{
[MenuItem("Assets/Reimport UI Assemblies", false, 100)]
public static void ReimportUI()
{
#if UNITY_4_6
using System;
using System.Collections;
using System.Globalization;
using System.Text;
namespace Procurios.Public
{
/// <summary>
/// This class encodes and decodes JSON strings.
/// Spec. details, see http://www.json.org/
@benloong
benloong / pattern-examples.swift
Created January 21, 2016 02:01 — forked from terhechte/pattern-examples.swift
Swift pattern examples for the swift, for, and guard keywords
import Foundation
// 1. Wildcard Pattern
func wildcard(a: String?) -> Bool {
guard case _? = a else { return false }
for case _? in [a] {
return true
}