Skip to content

Instantly share code, notes, and snippets.

View audinue's full-sized avatar

Audi Nugraha audinue

  • Surabaya, Jawa Timur, Indonesia
View GitHub Profile
@audinue
audinue / Scanner.cs
Created July 5, 2022 19:47
.NET idiomatic scanner
using System;
using System.Text;
using System.IO;
public class Scanner
{
TextReader Reader;
StringBuilder Builder;
public Scanner(TextReader reader)
{
// Right associative
function makeAssign (left, entries, index) {
if (index < entries.length) {
var entry = entries[index]
switch (entry[0]) {
case '+=':
return {
type: 'AddAssign',
left: left,

SoundPool Implementation

Minimal garbage sound pool implementation for desktop JVM. Intended to be used for games.

Requirements

  • The supported audio file format is 44100Hz 16-bit PCM stereo.
  • The audio file should be stripped from its header (see StripWAV)

Scripts to enable/disable Adguard DNS on F660 router through telnet.

@audinue
audinue / resize.js
Created April 23, 2022 19:02
Resize fit/fill
/**
* @param {[number, number]} src
* @param {[number, number]} max
* @return {[number, number]}
*/
function fit (src, max) {
var ratio = Math.min(max[0] / src[0], max[1] / src[1])
return [src[0] * ratio, src[1] * ratio]
}
<script>
// Source: https://www.redblobgames.com/pathfinding/a-star/implementation.html
function search (map, start, goal, straight) {
var frontier = [[start, 0]]
var cameFrom = {}
var costSoFar = {}
cameFrom[start] = null
costSoFar[start] = 0
while (frontier.length > 0) {
const renderTriangles = (triangles, options) => {
options = {
eye: [0, 1, 1],
center: [0, 0, 0],
mode: 'both',
orbit: true,
...options
}
const wireframe = ([a, b, c]) => [a, b, b, c, c, a]
<canvas id="canvas" width="500" height="500"></canvas>
<script>
var mouseX = 0
var mouseY = 0
canvas.onmousemove = function (e) {
mouseX = e.offsetX
mouseY = e.offsetY
}
@audinue
audinue / pan-zoom.html
Created January 28, 2022 10:01
Simple viewport panning and zooming without the use of matrix.
<canvas id="canvas" width="500" height="500" style="border: 1px solid"></canvas>
<script>
var panX = 0
var panY = 0
var zoom = 1
draw()
function textBBox (text, attributes) {
var ns = 'http://www.w3.org/2000/svg'
var svg = document.createElementNS(ns, 'svg')
var svgText = document.createElementNS(ns, 'text')
for (var name in attributes) {
svgText.setAttribute(name, attributes[name])
}
svgText.textContent = text
svg.appendChild(svgText)
svg.style.position = 'fixed'