Skip to content

Instantly share code, notes, and snippets.

View AnastasiaDunbar's full-sized avatar
🈚
­

Anastasia Dunbar AnastasiaDunbar

🈚
­
View GitHub Profile

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:

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

Ideas for new JavaScript language features.

These are some of my syntactic sugar ideas for JavaScript.

The #define macro 😐

#define add(a,b) a+b
console.log(add(4,7)); //Will output 11.
#define array [2,3]
console.log(array.pop()+array[1]); //Will output 6.
{
"Drum machines":[
{"name":"Roland TR-606 Drumatix","description":"A programmable analog synthesis drum machine."},
{"name":"Roland TR-707 Rhythm Composer","description":"A programmable digital sample-based drum machine."},
{"name":"Roland TR-808 Rhythm Composer","description":"An analog subtractive synthesis drum machine."},
{"name":"Roland TR-909 Rhythm Composer","description":"A drum machine with samples alongside analog sounds."},
{"name":"Korg Volca Beats","description":"An analog drum machine."},
{"name":"Akai MPC60","description":"An electronic sampler."},
{"name":"Pearl Fightman Electronic Training Drum","description":"An analog FM drum synth module."}
],
@AnastasiaDunbar
AnastasiaDunbar / Real-time audio processing.js
Last active February 7, 2019 11:00
DIY and no more libraries.
function dsp(time){
var master=Math.sin(Math.PI*2*440*time)*Math.exp(-3*time);
return master;
}
var audioContext=new AudioContext(),
bufferSize=2048, //256,512,1024,2048,4096,8192,16384
node=audioContext.createScriptProcessor(bufferSize,0,2), //bufferSize,inputChannels,outputChannels
time=0;
node.onaudioprocess=event=>{
var L=event.outputBuffer.getChannelData(0),
import PIL
from PIL import Image
from PIL import ImageGrab
import os
while(True):
while(True):
imageName=input("Enter filename: ")
if(os.path.isfile(imageName)): #File exists?
image=Image.open(imageName)
break
// - - Hello World - -
#include <iostream> //For input and output.
using namespace std; //"std::cout" into "cout".
int main(){
cout<<"Hello, world!\n";
return 0;
}
/*C version:
@AnastasiaDunbar
AnastasiaDunbar / Swedish word-to-number.js
Last active June 2, 2017 06:39
Ord till nummer (eller tal, jag vet inte och vem fan bryr sig). https://stackoverflow.com/a/12014376/4538129
var small={
"noll":0,
"ett":1, //Only idiots say "en" as a number.
"två":2,
"tre":3,
"fyra":4,
"fem":5,
"sex":6,
"sju":7,
"åtta":8,
@AnastasiaDunbar
AnastasiaDunbar / Alphabet.js
Last active July 5, 2018 20:34
Just an alphabet.
var alphabet=[
{letter:"a",consonant:false},
{letter:"b",consonant:true},
{letter:"c",consonant:true},
{letter:"d",consonant:true},
{letter:"e",consonant:false},
{letter:"f",consonant:true},
{letter:"g",consonant:true},
{letter:"h",consonant:true},
{letter:"i",consonant:false},