Skip to content

Instantly share code, notes, and snippets.

View scryptonite's full-sized avatar

Scryptonite scryptonite

View GitHub Profile
@scryptonite
scryptonite / parseTime.js
Created December 30, 2011 05:39
parseTime
function parseTime(time){
time = time.split(/(\,([ ]*and[ ]*)?|\;)/g);
var ms = 0;
for(var i = 0; i < time.length; i++){
var measure = time[i].trim();
switch(true){
case measure.search(/years?$/)>=0: ms+=parseFloat(measure, 10)*1000*60*60*24*365; break;
case measure.search(/months?$/)>=0: ms+=parseFloat(measure, 10)*1000*60*60*24*30; break;
case measure.search(/weeks?$/)>=0: ms+=parseFloat(measure, 10)*1000*60*60*24*7; break;
case measure.search(/days?$/)>=0: ms+=parseFloat(measure, 10)*1000*60*60*24; break;
@scryptonite
scryptonite / prox.js
Created July 29, 2012 23:44
Proxy for Worgy
var net = require("net");
var port = 25560; // the port it listens to
var target_host = "127.0.0.1"; // the host that receives the data
var target_port = 25575; // the port that receives the data
server = net.createServer(function(socket){
socket.pause()
var target = net.connect(target_port, target_host, function(){
socket.resume()
socket.on("data", function(data){
@scryptonite
scryptonite / packets.json
Created October 16, 2012 18:15
Packets in minecraft protocol 48
{
"meta": {
"protocol": 48,
"version": "1.4.3"
},
"00": {
"name": "Keep Alive",
"source": "B",
"structure": [
["int","keepAliveId"]

ppi.js

Uses the width, height, or diagonal length of a screen in inches to determine the pixels-per-inch.

Usage

Assumed environment would be a 21.5" iMac at 1920x1080 resolution.

var display = new Display({ diagonal: 21.5 }, window.screen);
@scryptonite
scryptonite / README.md
Last active December 16, 2015 09:59
close.js

close.js

Closes the current window (or popup).

Usage

window.close(); // current window is closed.
close(); // current window is closed.
close.call(window); // current window is closed.
@scryptonite
scryptonite / README.md
Last active December 16, 2015 18:40
randomizer.js
@scryptonite
scryptonite / now.lua
Last active December 22, 2015 01:28
Millisecond accurate time. I tried several concepts, most of it being wonky-calibration stuff that turned out to be inaccurate (micro leaps back in time). This is the one I am most satisfied with.
local function clock()
return (math.floor(os.clock() * 1000)/1000)
end
local _start_time = os.time()
local _start_clock = clock()
local _last
function now()
-- Sanity check. See http://lua-users.org/wiki/SleepFunction
@scryptonite
scryptonite / base.js
Created February 11, 2014 04:16
JavaScript Number::toString and parseInt for bases above 36.
function encode(input, base, map){
var num = input, arr = [], item;
if(typeof base != "number" && typeof base == "string" || Array.isArray(base)){
map = base;
base = map.length;
}
if(typeof base != "number") throw "Base must be a number";
if(typeof base < 2) throw "Base must be greater than 1";
while(num){
item = num % base;
@scryptonite
scryptonite / ChangeCursor.cs
Created August 28, 2016 04:24
LD36/Code/Scryptonite/ChangeCursor.cs
/*
* @Scryptonite
*
* Just attach this component to any GameObject with a Collider.
*
* If you end up using my cursor set, the hotspot is pretty good at <23, 26>.
*
* You might want to update the Texture Type of whatever cursor you use to "Cursor".
*
* Don't forget to update the default cursor and hotspot under Edit/Project Settings/Player.
using UnityEngine;
// Requires the MousePointer script if you plan on having the mouse be restored to its former position when released from being locked.
/// <summary>A Camera Controller that allows the user to pan/orbit and zoom around a target with their mouse.</summary>
[DisallowMultipleComponent, AddComponentMenu("Camera Controllers/Better Mouse Orbit")]
public class BetterMouseOrbit : MonoBehaviour {
#region Enumerations