Skip to content

Instantly share code, notes, and snippets.

View JLChnToZ's full-sized avatar
🥽
From game to XR experience

Jeremy Lam aka. Vistanz JLChnToZ

🥽
From game to XR experience
View GitHub Profile
@JLChnToZ
JLChnToZ / runscript.js
Created August 13, 2016 04:18
Similar to eval(), but it is safe to be called in strict mode and will run the code asynchronously (Nothing will be returned).
// Similar to eval(), but it is safe to be called in strict mode and will
// run the code asynchronously (Nothing will be returned).
// Available only in HTML5 DOM.
function runScript(script) {
if(!script) return;
// Create a temporary blob that contains the script string and
// add a script tag at the end of the document to contain that blob.
var blob = new Blob([script.toString()], { type: 'text/javascript' });
var url = URL.createObjectURL(blob);
@JLChnToZ
JLChnToZ / selfexpand.bat
Created September 10, 2016 08:09
Self expanding batch file
@echo off
echo "Self Expanding"
type %~f0 >> %~f0
rem The empty line at the end is important, or it will not works
@JLChnToZ
JLChnToZ / SelfDestructor.cs
Last active September 10, 2016 13:05
Simple script which will self destruct after executing.
using System;
using System.IO;
using System.Diagnostics;
using System.Reflection;
namespace SelfDestruct {
public class SelfDestructor {
const string batScript = "@echo off\r\n" +
":trydelete\r\n" +
"echo \"%~f1\">\"%~f1\"\r\n" +
@JLChnToZ
JLChnToZ / BMS.cs
Last active November 8, 2016 03:01
A Generic BM98 Format Loader and Runner for XNA. Buggy stuff and not accurate. See https://github.com/JLChnToZ/Bemusilization for newer implementations.
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;
@JLChnToZ
JLChnToZ / format-compare.md
Last active January 24, 2017 13:59
Text Format in Different Platforms Comparison

Text Format in Different Platforms Comparison

Expected Result [HTML][htmlformat] *1 [Unity3D Rich Text][u3dformat] [BBCode][bbcode] *1 [Markdown][markdown] *1 [Plurk Formatting Syntax][plurkformat] [Minecraft][mcformat]
Bold <strong>Bold</strong>
<b>Bold</b>
<b>Bold</b> [b]Bold[/b] **Bold**
__Bold__
**Bold** §lBold
Italic <em>Italic</em>
<i>Italic</i>
<i>Italic</i> [i]Italic[/i] *Italic*
_Italic_
*Italic* §oItalic
Underline <u>Underline</u> N/A [u]Underline[/u] N/A *2 _Underline_ §nunderline
Censored <del>Censored</del>
<s>Censored</s>
N/A [s]Censored[/s] ~~Censored~~ --Censored-- §mCensored
Big <font size="5">Big</font>
<big>Big</big>
<size=24>Big</size>*3 [size=24]Big[/size] N/A *2 N/A N/A
Small `<font size=
@JLChnToZ
JLChnToZ / MoserDeBruijn.cs
Last active February 1, 2017 04:08
Moser–de Bruijn Sequence lookup and inverse lookup.
public static class MoserDeBruijn {
private const int MaxValue = int.MaxValue;
public static int Lookup(int x, int y) {
if(x < 0 || y < 0) return 0;
int result = 0;
for(int mask = 1, offset = 0; (x >= mask || y >= mask) && mask < MaxValue; mask <<= 1)
result |= (x & mask) << offset++ | (y & mask) << offset;
return result;
}
@JLChnToZ
JLChnToZ / click-anywhere-gacha.js
Last active February 23, 2017 07:48
Click anywhere on the webpage to gacha :)
// Click-to-Gacha easter egg module for web pages
// (C) Jeremy Lam 2017.
// Require RandomJs and FingerPrintJs2 module in order to work
// You can change the behaviour in 'setTitle' and 'notify' function.
(function (root, factory) {
if(typeof define === 'function' && define.amd)
define(['random', 'fingerprintjs2'], factory);
else if(typeof module === 'object' && module.exports)
factory(require('random-js'), require('fingerprintjs2'));
@JLChnToZ
JLChnToZ / test-ast.js
Last active April 7, 2017 11:15
An Operator-precedence parser, Abstract Syntax Tree and Stack Machine Experiment
(function(root, factory) {
if(typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['exports'], function(exports) {
factory((root.chocomilk = exports), b);
});
} else if(typeof exports === 'object' && typeof exports.nodeName !== 'string') {
// CommonJS
factory(exports);
} else {
@JLChnToZ
JLChnToZ / sync-promise.js
Last active April 24, 2017 02:44
Add support for promises with Node Sync.
// Add support for promises with Node Sync.
// https://github.com/ybogdanov/node-sync
(function() {
'use strict';
const { Fibers, Future } = module.exports = require('sync');
const slice = Function.prototype.call.bind(Array.prototype.slice);
if(typeof Promise !== 'undefined') {
// Pause execution and wait until the promise fufilled.
Promise.prototype.sync = function() {
@JLChnToZ
JLChnToZ / ScreenFork.cs
Last active June 27, 2017 14:07
Camera Fork
using UnityEngine;
[ExecuteInEditMode, RequireComponent(typeof(Camera))]
public class ScreenFork: MonoBehaviour {
public RenderTexture copyTo;
private void OnRenderImage(RenderTexture src, RenderTexture dest) {
Graphics.Blit(src, dest);
if(copyTo != null)