Skip to content

Instantly share code, notes, and snippets.

@xiaobin83
xiaobin83 / portable_endian.h
Created December 19, 2016 16:26 — forked from panzi/portable_endian.h
This provides the endian conversion functions form endian.h on Windows, Linux, *BSD, and Mac OS X. You still need to use -std=gnu99 instead of -std=c99 for gcc. The functions might actually be macros. Functions: htobe16, htole16, be16toh, le16toh, htobe32, htole32, be32toh, le32toh, htobe64, htole64, be64toh, le64toh. License: I hereby put "port…
// "License": Public Domain
// I, Mathias Panzenböck, place this file hereby into the public domain. Use it at your own risk for whatever you like.
// In case there are jurisdictions that don't support putting things in the public domain you can also consider it to
// be "dual licensed" under the BSD, MIT and Apache licenses, if you want to. This code is trivial anyway. Consider it
// an example on how to get the endian conversion functions on different platforms.
#ifndef PORTABLE_ENDIAN_H__
#define PORTABLE_ENDIAN_H__
#if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) && !defined(__WINDOWS__)
@xiaobin83
xiaobin83 / WebRequest2.cs
Last active December 28, 2016 15:12
Simple HttpWebRequest wrapper.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Text;
using common;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
namespace federation
@xiaobin83
xiaobin83 / UnitTest.lua
Created December 28, 2016 15:10
Simple unit test script.
local UnitTest = {}
local meta = { __index = UnitTest }
function UnitTest.New()
local inst = {
numTests = 0,
failed = {}
}
setmetatable(inst, meta)
@xiaobin83
xiaobin83 / Packet.lua
Created December 28, 2016 21:45
Reading/writing on bytearray
local Packet = {}
-- packet.data is a binary string
-- packet.pos is position of current reading pos
local str = string
local packetMeta = { __index = Packet, __len = function(p) return #p.data end }
function Packet.New(inData)
@xiaobin83
xiaobin83 / PlayingTest.cs
Last active December 29, 2016 21:53
copy & paste NUnit test code and run it on device
using UnityEngine;
using System.Linq;
using System;
using System.Reflection;
using System.Collections.Generic;
namespace playingtest
{
public class TestAttribute : Attribute
function HexDump(buf)
local s = {}
s.output = ''
for byte=1, #buf, 16 do
local chunk = buf:sub(byte, byte+15)
s.output = s.output .. string.format('%08X ',byte-1)
chunk:gsub('.', function (c) s.output = s.output .. string.format('%02X ',string.byte(c)) end)
s.output = s.output .. string.rep(' ',3*(16-#chunk))
s.output = s.output .. chunk:gsub('%c','.') .. "\n"
end
@xiaobin83
xiaobin83 / fla2swf.py
Created January 10, 2017 09:26
batched exporting fla 2 swf
import os
import sys
import fnmatch
FlashExe= r'"D:\opt\FlashCS6\Adobe Flash CS6\Flash.exe"'
def collectAllFla(fla, dirname, names):
for n in names:
p = os.path.join(dirname, n)
@xiaobin83
xiaobin83 / Timer.lua
Created October 1, 2017 17:15
timing wheel
-- https://blog.acolyer.org/2016/11/23/hashed-and-hierarchical-timing-wheels/
-- Scheme 6
local Timer = {}
local kMaxIntervalShift = 4 --> 1 << kMaxIntervalShift seconds
local kMaxSlots = 1 << kMaxIntervalShift
local kSlotsMask = kMaxSlots - 1
local origin = os.clock()
local pointer = 0
@xiaobin83
xiaobin83 / texture_blending.fx
Created October 10, 2017 03:40
MAX shader of texture blending
// This is used by 3dsmax to load the correct parser
string ParamID = "0x0";
float FixedLightmapIntensity = 1.5;
int texcoord0 : Texcoord
<
int Texcoord = 0;
int MapChannel = 1;
@xiaobin83
xiaobin83 / BitmapFontWizard.cs
Created October 11, 2017 10:55
Unity3D Bitmap generator
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine.Sprites;
public class BitmapFontWizard : ScriptableWizard {
public Texture2D fontTexture;