Skip to content

Instantly share code, notes, and snippets.

View Muscipular's full-sized avatar

Muscipular Muscipular

View GitHub Profile
/*
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace
so it's better encapsulated. Now you can have multiple random number generators
and they won't stomp all over eachother's state.
If you want to use this as a substitute for Math.random(), use the random()
method like so:
var m = new MersenneTwister();
@Muscipular
Muscipular / ?
Last active June 21, 2016 03:07
web
var k = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 30, 40, 50, 60, 70, 80, 90, 100, 1000];
var w = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety', 'Hundred', 'Thousand'];
var wl = {};
var i, j, k, o;
for (i = 0; i < w.length; i++) {
wl[k[i].toString()] = w[i];
}
var mx = 1000;
@Muscipular
Muscipular / EvHandler
Last active June 15, 2018 01:21
SimpleMessager for worker
let eventEmitter = require("events").EventEmitter;
class EvHandler extends eventEmitter {
constructor(process) {
super();
let listener = this.onMessage.bind(this);
process.on("message", listener);
let clear = () => {
this.cbs = null;
this.removeAllListeners();
var SHAKE_THRESHOLD = 800;
var last_update = 0;
var x = y = z = last_x = last_y = last_z = 0;
if (window.DeviceMotionEvent) {
window.addEventListener('devicemotion', deviceMotionHandler, false);
} else {
alert('本设备不支持devicemotion事件');
}
@Muscipular
Muscipular / EnumUtils
Last active June 16, 2016 12:38
EnumUtils
public abstract class EnumClassUtils<TClass>
where TClass : class
{
public static TEnum Parse<TEnum>(string value)
where TEnum : struct, TClass
{
return (TEnum) Enum.Parse(typeof(TEnum), value);
}
window.execEx = function(fn, maxTime) {
return new Promise(function (resolve, reject) {
var timer = setTimeout(function () {
if(timer) {
timer = false;
console.log('reject');
reject();
}
}, maxTime);
var f = function() {
@Muscipular
Muscipular / redis-cli-ssl.js
Created March 23, 2018 07:16
redis-cli-ssl
#!/usr/local/bin/node
const { execSync, exec, spawn, spawnSync } = require('child_process');
const { writeFileSync, unlinkSync } = require('fs');
process.on('uncaughtException', e => LogError(e));
const config = `/tmp/stunnel-${Date.now()}${Math.random()}.conf`;
const port = parseInt(Math.random() * 20000) + 30000;
let stunnel = null;
const quiet = process.argv.indexOf("---Q") >= 0;
const debug = !quiet && process.argv.indexOf("---D") >= 0;
#!/usr/local/bin/node
let { execSync } = require('child_process')
let args = process.argv.slice(2)
let host = ''
let port = ''
let format = 'split'
for (let i = 0; i < args.length; i++) {
@Muscipular
Muscipular / README.md
Last active September 3, 2018 05:45
redis-cli python implement support ssl and cluster mode

redis command line interface like redis-cli support ssl and cluster mode

dependence: python3.6+, redis, prompt_toolkit

install

pip install redis
pip install prompt_toolkit==1.0.15
@Muscipular
Muscipular / MonoGameFontUtil.cs
Last active September 9, 2022 04:13
monogame dynamic draw font, using SharpFont, and cache with texture2d
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using SharpFont;
namespace MonoFont
{