Skip to content

Instantly share code, notes, and snippets.

View JLChnToZ's full-sized avatar

Jeremy Lam aka. Vistanz JLChnToZ

View GitHub Profile
@JLChnToZ
JLChnToZ / global.d.ts
Last active June 6, 2018 11:57
Demo for workaround on writing tsx file without React but with Hyperscript.
declare module '__globals' {
type DomElement = Element;
type DeepPartial<T> = {
[K in keyof T]?: T[K] | DeepPartial<T[K]>;
};
type FreePartialProperties<T> = {
[K in keyof T]: DeepPartial<T[K]> & {
[key: string]: any;
};
};
@JLChnToZ
JLChnToZ / syncgif.js
Created January 14, 2018 14:16
A little script for refreshing all gifs on a webpage to make them synchronized.
(function refreshGif(selector, images, srcs) {
var mode = !!srcs, i;
if(mode) {
for(i = 0; i < images.length; i++)
images[i].src = srcs[i];
return;
}
var dummyGif = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
images = document.querySelectorAll((selector || '') + ' img[src$=\'.gif\']');
srcs = [];
@JLChnToZ
JLChnToZ / ninjectscript.js
Last active December 7, 2017 16:31
Inject external JavaScript like a ninja
var ninjectScript = (function(window, document) {
var head = document.head || document.getElementsByTagName('head')[0],
BlobBuilder,
builderPrefixes = [
'webkit', 'Webkit', 'WebKit',
'moz', 'Moz', 'o', 'O',
'ms', 'Ms', 'MS',
'khtml', 'Khtml', ''
];
@JLChnToZ
JLChnToZ / smartflatten.js
Created October 12, 2017 18:01
Simple Node.js script which simplify nested directory tree
'use strict';
const fs = require('fs');
const path = require('path');
let directories = process.argv.slice(2).map(resolveDir);
while(directories.length) {
const subDir = [];
for(const dir of directories) {
if(!ensureFolder(dir)) continue;
@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)
@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 / 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 / Whitespace.Compiler.cs
Last active October 26, 2021 09:56
Whitespace Language Compiler for .NET
using System;
using System.IO;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using Whitespace.Utils;
namespace Whitespace {
public delegate void CompiledMethod(TextReader input, TextWriter output);
@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;
}