Skip to content

Instantly share code, notes, and snippets.

Avatar
🈚
­

Anastasia Dunbar AnastasiaDunbar

🈚
­
View GitHub Profile
View 2D matrix math functions.js
function multiplyMatrix(a,b){
var o=[];
for(var i=0;i<a.length;i++){
o[i]=[];
for(var j=0;j<b[0].length;j++){
var s=0;
for(var k=0;k<a.length;k++){s+=a[i][k]*b[k][j];}
o[i][j]=s;
}
}
View Raster font editor.p5.js
function clamp(x,minVal,maxVal){return Math.min(Math.max(x,minVal),maxVal);}
function pointInRect(px,py,x,y,w,h){return px>=x&&py>=y&&px<x+w&&py<y+h;}
function drawASCIItable(x,y,w,h,columns=8,fromChar=32,toChar=126){
stroke(255);noFill();
rect(x,y,w,h);
if(user.click){user.ASCIItableClicked=pointInRect(mouseX,mouseY,x,y,w,h);}
var charCount=(toChar-fromChar)+1;
for(var i=1;i<columns;i++){
line(x+(i/columns)*w,y,x+(i/columns)*w,y+h);
}
View Arbitrary-sized minifloats.js
//Note: JavaScript bitwise operators can only handle 32 bits, and 31st bit is used as a sign bit (use `x>>>0` to unsign it).
//Note: `1<<x` is sometimes used like an alternative to `2**x` (or `Math.pow(2,x)`) here.
//sign , (exponent bit)*eb , (mantissa bit)*mb.
function customFloatSize(eb,mb){return eb+mb+1;}
function maximumFloatNumber(eb,mb){let e=1<<(((1<<eb)-2)-1);return e+(e*(1-(1/(1<<mb))));}
function fromCustomFloat(x,eb,mb){
let sign=(x>>>(eb+mb))&1?-1:1,
maxExp=(1<<eb)-1,
expBits=(x>>>mb)&maxExp,
@AnastasiaDunbar
AnastasiaDunbar / store(code); bookmarklet.js
Last active Jul 14, 2020
A bookmarklet to save current page's code/form, like a textarea cache (except it doesn't save automatically).
View store(code); bookmarklet.js
javascript:(()=>{
let magic="store(code);",hn=location.hostname,d=document,qS=(s,o=document)=>o.querySelector(s),
element,value,description=[new Date().getTime()];
if(/openprocessing\.org/.test(hn)){
element=codeMirror;
value=element.getValue();
}else if(/(wavepot|tinyrave)\.com/.test(hn)){
element=ace.edit("editor").getSession();
value=element.getValue();
}else if(/mytextarea\.com/.test(hn)){
View How to enable Developer Mode on Chromebook.md

Before enabling Developer Mode, archive your 'Downloads' folder, bookmarks, passwords, cache, add-ons, themes, apps, history, settings, custom words for spell check and etc. if you'd wish to keep your data.

Remember to disable Developer Mode before getting warranty support, this would also go through the same powerwash process.

Before setting up Linux (Beta), note that your Chromebook typically protects your computer by running each app in a “sandbox”. However, all Linux apps are run inside the same sandbox. This means a harmful Linux app can affect other Linux apps, but not the rest of your Chromebook. Permissions and files shared with Linux are available to all Linux apps. But speakers, microphones, cameras, USB devices/debuggers, Android Studio, emulators, hardware acceleration, GPU and video decoding aren't yet supported.

Steps to enable Developer Mode on your Chromebook:

  1. Press and hold Esc+Refresh+Power simultaneously.
  2. Press Ctrl+D when asked to insert recovery media.
  3. Press Enter on “To turn
View Audio filter.js
const LOWPASS=0,HIGHPASS=1,BANDPASS=2;
class Filter{
constructor(mode){
this.cutoff=.99;
this.resonance=0;
this.mode=mode;
this.b0=0;this.b1=0;this.b2=0;this.b3=0;
this.feedbackAmount=0;
this.cutoffMod=0;
View Interval timer without setInterval().js
function mod(a,b){return((a%b)+b)%b;}
class Timer{
constructor(callback,delay,tickBy=1,...parameters){
this.callback=callback;
this.duration=delay;
this.timer=delay;
this.tickBy=tickBy;
this.parameters=parameters;
}
tick(){
View Problems in programming languages IMO.md

JavaScript

Automatic semicolon insertion

I embrace semicolons myself and it's more readable too. But the automatic semicolon insertion just might be useful in code golfing scenarios? In this example:

return
something;

will be converted into:

View Node.js Hello, World.js
process.stdin.resume(); //Keep process from terminating.
const readline=require("readline"),
rl=readline.createInterface({
input:process.stdin,
output:process.stdout
});
function question(string){
return new Promise(resolve=>
rl.question(string+"\n",answer=>resolve(answer))
);
View TIC-80 Perlin Noise.js
// title: Perlin Noise
// author: Anastasia Dunbar
// script: js
var width=240,height=136;
function mix(a,b,t){return(t*(b-a))+a;}
function mod(a,b){return((a%b)+b)%b;}
function fract(x){return x-Math.floor(x);}
function clamp(a,b,c){return Math.min(Math.max(a,b),c);}
function dot(a,b){for(var s=0,i=0;i<a.length;i++){s+=a[i]*b[i];}return s;}
function sign(x){return x>0?1:x<0?-1:0;}