Skip to content

Instantly share code, notes, and snippets.

@seleb
seleb / expose.js
Created January 19, 2018 04:35
Expose getter/setter for private vars
var expose = function (target) {
var code = target.toString();
code = code.substring(0, code.lastIndexOf("}"));
code += "this.get = function(name) {return eval(name);};";
code += "this.set = function(name, value) {eval(name+'=value');};";
return eval("[" + code + "}]")[0];
};
@seleb
seleb / inject.js
Created February 8, 2018 05:33
inject code into script tags based on a search string
// helper used to inject code into script tags based on a search string
var inject = function (searchString, codeToInject) {
// find the relevant script tag
var scriptTags = document.getElementsByTagName('script');
var scriptTag;
var code;
for (var i = 0; i < scriptTags.length; ++i) {
scriptTag = scriptTags[i];
if (
scriptTag.textContent.indexOf(searchString) >= 0 // script contains the search string
@seleb
seleb / pixelated.css
Created March 3, 2018 01:28
image-rendering: pixelated
{
image-rendering: optimizeSpeed;
image-rendering: -webkit-crisp-edges;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: optimize-contrast;
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
@seleb
seleb / clearDir.js
Created March 19, 2018 02:42
Deletes all files in a directory with a given extension
const path = require("path");
const fs = require("fs");
function clearDir(dirPath, ext) {
fs.readdirSync(dirPath)
.filter(filePath => path.extname(filePath) === ext)
.forEach(filePath => {
filePath = path.join(dirPath, filePath);
try {
fs.unlinkSync(filePath);
@seleb
seleb / ASCII extended
Last active March 29, 2018 04:50
there are lots of tables of these; hard to find just a single string with them all lined up though
0-31,127: control characterss
32-126: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
1-31 IBM PC:☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼
128-255 IBM PC:ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■
128-255 ISO Latin-1:€ ‚ƒ„…†‡ˆ‰Š‹Œ Ž ‘’“”•–—˜™š›œ žŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
0-255 IBM PC (escaped unicode):\u0000\u263A\u263B\u2665\u2666\u2663\u2660\u2022\u25D8\u25CB\u25D9\u2642\u2640\u266A\u266B\u263C\u25BA\u25C4\u2195\u203C\u00B6\u00A7\u25AC\u21A8\u2191\u2193\u2192\u2190\u221F\u2194\u25B2\u25BC\u0020\u0021\u0022\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002a\u002b\u002c\u002d\u002e\u002f\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047\u0048\u0049\u004a\u004b\u004c\u004d\u004e\u004f\u0050\u0051\u0052\u0053\u0054\u0055\u0056
@seleb
seleb / unicodeToAsciiExtended.js
Last active March 29, 2018 04:47
provides an object which maps unicode characters to extended ascii codepoints (IBM PC/code page 437)
var unicodeToAsciiExtended = "\u0000\u263A\u263B\u2665\u2666\u2663\u2660\u2022\u25D8\u25CB\u25D9\u2642\u2640\u266A\u266B\u263C\u25BA\u25C4\u2195\u203C\u00B6\u00A7\u25AC\u21A8\u2191\u2193\u2192\u2190\u221F\u2194\u25B2\u25BC\u0020\u0021\u0022\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002a\u002b\u002c\u002d\u002e\u002f\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039\u003a\u003b\u003c\u003d\u003e\u003f\u0040\u0041\u0042\u0043\u0044\u0045\u0046\u0047\u0048\u0049\u004a\u004b\u004c\u004d\u004e\u004f\u0050\u0051\u0052\u0053\u0054\u0055\u0056\u0057\u0058\u0059\u005a\u005b\u005c\u005d\u005e\u005f\u0060\u0061\u0062\u0063\u0064\u0065\u0066\u0067\u0068\u0069\u006a\u006b\u006c\u006d\u006e\u006f\u0070\u0071\u0072\u0073\u0074\u0075\u0076\u0077\u0078\u0079\u007a\u007b\u007c\u007d\u007e\u007f\u00c7\u00fc\u00e9\u00e2\u00e4\u00e0\u00e5\u00e7\u00ea\u00eb\u00e8\u00ef\u00ee\u00ec\u00c4\u00c5\u00c9\u00e6\u00c6\u00f4\u00f6\u00f2\u00fb\u00f9\u00ff\u00d6\u00dc\u00a2\u00a3\u00a5\u20a7\u0192\u00e1\u00ed\u00f3\u00fa\u00f1\u00
@seleb
seleb / grid paths.lua
Created April 22, 2018 01:41
All horizontal, vertical, and diagonal paths on a grid
grid=7 --8x8
paths={}
--horizontal
for y=0,grid do
local p={}
for x=0,grid do
add(p,{x=x,y=y})
end
add(paths,p)
end
@seleb
seleb / rand-pico-pal.js
Last active April 22, 2018 23:43
Generates a random pico-8 palette
var a=[];
for(var i = 0; i<16; ++i){
a.push(i);
}
var b=[];
while(a.length){
b.push(a.splice(Math.floor(Math.random()*a.length),1));
}
`{${b.join(',')}}`;
@seleb
seleb / s-tengine2 asset convert.js
Last active May 27, 2018 21:15
one-liner for generating a set of es6 import/exports from an s-tengine2 scenario
assets.map(asset=>`export { default as ${asset.id} } from './${asset.src}'`).join(";\n");
@seleb
seleb / bitsy tile loop.js
Created June 4, 2018 04:50
create gamedata for a looping bitsy tile animation
////////////
// config //
////////////
const tileStr = `
00000000
00000000
00100100
00100100
00000000
01000010