Skip to content

Instantly share code, notes, and snippets.

View jonathanlurie's full-sized avatar
🐛
I like to code things

Jonathan Lurie jonathanlurie

🐛
I like to code things
View GitHub Profile
@jonathanlurie
jonathanlurie / jsont.js
Last active November 26, 2024 07:28
Serialize/deserialize json and conserve typed arrays
/*
Author: Jonathan Lurie - http://me.jonathanlurie.fr
License: MIT
The point of this little gist is to fix the issue of losing
typed arrays when calling the default JSON serilization.
The default mode has for effect to convert typed arrays into
object like that: {0: 0.1, 1: 0.2, 2: 0.3} what used to be
Float32Array([0.1, 0.2, 0.3]) and once it takes the shape of an
object, there is no way to get it back in an automated way!
@jonathanlurie
jonathanlurie / index.html
Created September 17, 2017 20:31
play audio in JS
<html>
<head>
</head>
<body>
<script>
// index of the sound currently being played (-1 if none)
var playingIndex = -1;
// duration in second of the fading
var fadeDuration = 2;
@jonathanlurie
jonathanlurie / endianness.js
Last active July 12, 2017 00:38 — forked from TooTallNate/endianness.js
Get host machine endianness using JavaScript Typed Arrays (polyfill for `os.endianness()` in node.js)
function endianness () {
var b = new ArrayBuffer(4);
var a = new Uint32Array(b);
var c = new Uint8Array(b);
a[0] = 0xdeadbeef;
if (c[0] == 0xef) return 'LE';
if (c[0] == 0xde) return 'BE';
throw new Error('unknown endianness');
}
@jonathanlurie
jonathanlurie / data-3.csv
Last active May 25, 2017 03:06 — forked from d3noob/data-3.csv
v4 curve interpolation comparison
date close
1-May-12 558.13
30-Apr-12 553.98
27-Apr-12 567.00
26-Apr-12 589.70
25-Apr-12 599.00
24-Apr-12 630.28
21-Apr-12 666.70
23-Apr-12 666.70
20-Apr-12 634.98
@jonathanlurie
jonathanlurie / index.html
Created April 6, 2017 17:48
starter THREE + Orbit
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Three.js Geometry Browser</title>
<style>
body {
@jonathanlurie
jonathanlurie / index.html
Last active March 21, 2017 17:28
Hides the cursor after 2 seconds, then show again when moving. https://bl.ocks.org/jonathanlurie/f7261e717fc94063b4992fcecb71ba69
<html>
<head>
</head>
<body>
Hides the cursor after 2 seconds, then show again when moving.
<script>
(function() {
@jonathanlurie
jonathanlurie / arrayFunction.cpp
Created March 10, 2017 22:01
Emscripten and float arrays v3
#include <math.h>
// otherwise C++ function names are mangled
extern "C" {
void float_multiply_array(float *data, int w, int h, int ncpp) {
int length = w*h;
int currentPixelIndex = 0;
int currentPixelIndexUnderFilter = 0;
@jonathanlurie
jonathanlurie / arrayFunction.cpp
Created March 10, 2017 20:56
Emscripten and float arrays v2
#include <math.h>
// otherwise C++ function names are mangled
extern "C" {
void float_multiply_array(float *data, int w, int h, int ncpp) {
int length = w*h;
int currentPixelIndex = 0;
@jonathanlurie
jonathanlurie / arrayFunction.cpp
Last active May 31, 2023 10:22
Emscripten and float arrays
#include <math.h>
// otherwise C++ function names are mangled
extern "C" {
int float_multiply_array(float factor, float *arr, int length) {
for (int i = 0; i < length; i++) {
arr[i] = factor * arr[i];
}
<html>
<head>
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
<script src="http://imagesloaded.desandro.com/imagesloaded.pkgd.js"></script>
<style>
* { box-sizing: border-box; }
/* force scrollbar */