Skip to content

Instantly share code, notes, and snippets.

@nicoptere
nicoptere / lol()
Last active August 29, 2015 14:05
lol() : improving the console.log through dynamic LULZ injection
/**
* lol()
* improving the console.log through dynamic LULZ injection
*
* history
* - v0.0 RC - 2014-08-08 - 13h01 : initial release
* - v0.1 RC - 2014-08-08 - 13h29 : DogeScript support
*
* Licensed under WTFPL
*
@nicoptere
nicoptere / PRNG
Last active February 6, 2020 08:32
Mersenne Twister: a good Pseudo Random Number Generator ( PRNG )
/*
from : http://en.wikipedia.org/wiki/Mersenne_twister
*/
let MT
let index
class PRNG {
static setSeed(seed) {
// Create a length 624 array to store the state of the generator
MT = new Uint32Array(624)
index = 0
@nicoptere
nicoptere / imageProxy.php
Last active December 27, 2023 17:30
basic PHP image proxy (that works ... )
<?php
$url = "";
if( isset( $_GET['url'] ) )
{
$url = $_GET[ 'url' ];
}
else
{
@nicoptere
nicoptere / THREE.js lon_lat_to_cartesian
Last active January 16, 2023 09:56
methods to convert longitude / latitude to XYZ and back + utility polygon contains point for THREE.js
/**
* converts a XYZ vector3 to longitude latitude (Direct Polar)
* @param lng longitude
* @param lat latitude
* @param vector3 optional output vector3
* @returns a unit vector of the 3d position
*/
function lonLatToVector3( lng, lat, out )
{
out = out || new THREE.Vector3();
@nicoptere
nicoptere / bitmasking
Created October 14, 2014 16:00
bit masking, basic operations
/**
* checks if a value has a given bit set to 1
* @value the int / uint to test
* @mask the bits to check
**/
function bit_isset( value, mask )
{
return ( value & mask ) != 0;
}
@nicoptere
nicoptere / float triplets sorting method
Last active August 29, 2015 14:08
sorting triplets of floats in a buffer (vertices, indices, normals etc. ) using the QuickSort method.
/*
the quick sort method is described here :
http://antjanus.com/blog/web-development-tutorials/understanding-quicksort-js-native-implementation/
*/
function tripletSort( arr )
{
@nicoptere
nicoptere / canvas noise
Created January 21, 2015 13:15
noise function for canvas
/**
* creates a noise on the specified 2d context's canvas
* @ctx a 2d context
* @rgba color code specifies which channels are affected (default = 0 )
* @min noise lower bound ( >= 0 )
* @max noise upper bound ( <= 0xFF )
* */
function noise( ctx, rgba, min, max )
{
@nicoptere
nicoptere / log caller
Created January 28, 2015 14:04
tries to log the function caller
var console = (window.console = window.console || {});
var original = console[ 'log' ];
console[ "log" ] = function()
{
var args = Array.prototype.slice.apply( arguments );
original.apply( console, args );
try
{
throw new Error();
}
@nicoptere
nicoptere / dijkstra
Created March 15, 2015 10:33
dijkstra algorithm ( brutal implementation )
function dijkstra( graph_array, source, target)
{
//builds adjacency list
var vertices = [];
var neighbours = {};
graph_array.forEach( function( edge )
{
//store the vertex 0
@nicoptere
nicoptere / essentials.js
Last active March 24, 2018 12:11
essentials
<style>
html, body{
width:100%;
height:100%;
overflow: hidden;
top:0;
left:0;
margin:0;
padding:0;
}