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 / closest.js
Last active May 24, 2023 18:57
Closest 3D point on triangle. Expanded from SharpDX implementation.
function closest (result, p, a, b, c) {
var px = p[0]
var py = p[1]
var pz = p[2]
var ax = a[0]
var ay = a[1]
var az = a[2]
var bx = b[0]
var by = b[1]
var bz = b[2]
@audinue
audinue / socket.java
Created March 12, 2023 04:12
AutoServer AutoClient
import java.io.*;
import java.net.*;
abstract class Client
{
Socket socket;
ObjectOutputStream out;
boolean closed;
void init(final Socket newSocket) {
package com.example.notification;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
@audinue
audinue / scaleToFit.js
Created November 27, 2022 01:25
Scale to fit
function scaleToFit (
contentWidth,
contentHeight,
containerWidth,
containerHeight
) {
var scale = Math.min(containerWidth / contentWidth, containerHeight / contentHeight)
return {
x: containerWidth / 2 - contentWidth * scale / 2,
y: containerHeight / 2 - contentHeight * scale / 2,
function uuidv4() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
console.log(uuidv4());
@audinue
audinue / bitmap.c
Created July 24, 2022 21:38
Load bitmap using GDI+ in C
#include <stdlib.h>
#include <windows.h>
#include <gdiplus.h>
Bitmap* loadBitmap(char* file)
{
int length = strlen(file) + 1;
wchar_t* fileW = (wchar_t*) malloc(length * sizeof(wchar_t));
#include <stdlib.h>
#include <string.h>
typedef struct Entry {
char* key;
void* value;
int next;
} Entry;
typedef struct Map {
#include <stdlib.h>
#include <string.h>
#define CAPACITY 100000
typedef struct Entry {
char* key;
void* value;
struct Entry* next;
} Entry;
#include <stdlib.h>
#include <string.h>
#define CAPACITY 4096
typedef struct Entry {
char* key;
void* value;
struct Entry* next;
} Entry;
@audinue
audinue / SimpleSleepSync.c
Last active July 12, 2022 14:36
Common game loop's sleep
#include <windows.h>
void SleepSync(int targetFps)
{
static DWORD previous = 0;
if (previous == 0)
previous = GetTickCount();
LONGLONG current = GetTickCount();
LONGLONG sleepTime = (1000 / targetFps) - (current - previous);
previous = current;