Skip to content

Instantly share code, notes, and snippets.

View scryptonite's full-sized avatar

Scryptonite scryptonite

View GitHub Profile
@scryptonite
scryptonite / _.js
Last active May 12, 2020 20:08
for giving TTsBeastie's command parameter parser the superpower of understanding long strings that contain spaces
// turns `first second "third fourth fifth"` into ["first", "second", "third fourth fifth"].length === 3
const getParameters = message => Array.from((function*(string){
console.log(string);
const encapsulator = ["\"", "'", "`"];
const escape = "\\";
for(let index = 0; index < string.length; index++){
const start = index;
const part = string[index];
@scryptonite
scryptonite / 0_README.md
Last active October 24, 2019 01:52
Dumps all Sequelize models to JSON to help with creating the first migration script.
  1. Modify & run dump-sequelize-schema.js.
    • It currently uses a few lodash methods, so be sure to temporarily install them—or if you feel up to it you can rewrite the script so they're not needed.
    • npm i lodash.sortby lodash.pick lodash.omit lodash.mapvalues
  2. Inspect sequelize-schema.json and make sure it appears represent all of your tables, attributes, indexes, constraints, references, etc...
  3. When you are satisfied, copy and rename sequelize-schema.json file into a migration-extras/ directory that is next to your migrations/. Name it initial-sequelize-schema.json.
    • migration-extras/
      • -> initial-sequelize-schema.json
    • migrations/
      • (this folder should probably be empty)
  4. Run sequelize migration:create and then copy the contents of 2018XXXXXXXXXX-initial-migration.js into the newly generated migration script. No additional modifications are required if y
using UnityEngine;
// Adds a backface to the mesh on Start()
// Source: http://answers.unity3d.com/answers/280931/view.html
public class BackfaceMesh : MonoBehaviour {
public void Start () {
var mesh = GetComponent<MeshFilter>().mesh;
var vertices = mesh.vertices;
var uv = mesh.uv;
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
@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.
@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 / 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 / README.md
Last active December 16, 2015 18:40
randomizer.js
@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.

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);