Skip to content

Instantly share code, notes, and snippets.

@rgrove
rgrove / rc4.js
Created June 1, 2009 22:17
RC4-drop[256] (aka MARK-4) implementation in JavaScript. Minifies to 511 bytes using YUI Compressor.
/**
* RC4-drop[256] (aka MARK-4) implementation in JavaScript.
*
* @module rc4
*/
/**
* @class RC4
* @static
*/
@Protonk
Protonk / prng.js
Last active August 31, 2024 17:14
Various PRNGs, implemented in javascript.
// Linear Congruential Generator
// Variant of a Lehman Generator
var lcg = (function() {
// Set to values from http://en.wikipedia.org/wiki/Numerical_Recipes
// m is basically chosen to be large (as it is the max period)
// and for its relationships to a and c
var m = 4294967296,
// a - 1 should be divisible by m's prime factors
a = 1664525,
// c and m should be co-prime
/* PROG1.C */
/* Simple Hashing LZ77 Sliding Dictionary Compression Program */
/* By Rich Geldreich, Jr. October, 1993 */
/* Originally compiled with QuickC v2.5 in the small model. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
/* set this to 1 for a greedy encoder */
@dinjas
dinjas / url_shortener.js
Last active November 24, 2018 09:17
Simple shortener of an integer string into a base62 string. Sample usage at bottom of each file.
var codeset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var base = codeset.length;
function encode(intStr) {
var hash = "";
intStr = parseInt(intStr);
while (intStr > 0) {
hash = self.codeset[parseInt(intStr % base)] + hash;
intStr = Math.floor(intStr / base);
}
@slembcke
slembcke / NearlyNearestNeighborFiltering.glsl
Last active December 27, 2020 21:19
Anti-aliased Nearest Neighbor Filtering.
uniform sampler2D texture;
varying vec2 uv;
void main(){
vec2 size = textureSize(texture);
vec2 puv = uv*size;
vec2 hfw = 0.5*fwidth(puv);
vec2 fl = floor(puv - 0.5) + 0.5;
@larsiusprime
larsiusprime / AABB.as
Created April 21, 2016 16:59
collision
package simulation.collision
{
import math.vec2;
public class AABB
{
public var min:vec2;
public var max:vec2;
public function AABB(xmin:Number, ymin:Number, xmax:Number, ymax:Number)