Skip to content

Instantly share code, notes, and snippets.

View nrkn's full-sized avatar

Nik nrkn

View GitHub Profile
@skorks
skorks / subset_sum_dynamic.rb
Created February 26, 2011 14:32
Solving the subset sum problem via dynamic programming
require 'terminal-table/import'
class SubsetSumMatrix
class << self
def create_empty_for(array)
matrix = []
header = [nil] + build_header_from(array)
matrix << header
array.each_with_index do |element,i|
row = header.collect{|value| 'F'}
@scottjehl
scottjehl / jqm-self-init-a-widget.js
Created July 8, 2011 14:29
Self-init a jQuery Mobile plugin
// First, let's define a widget/plugin called "foo"
// Either using jQuery's $.fn plugin namespace, for simple stateless plugins...
$.fn.foo = function(){
// In this scope, this refers to the element on which the plugin foo() was called
// manipulate it and return this at the end, so it can be chainable
};
@bert
bert / README
Created July 15, 2011 21:01
Bresenham Algorithms in C
Some possible implementations of the Bresenham Algorithms in C.
The Bresenham line algorithm is an algorithm which determines which points in an
n-dimensional raster should be plotted in order to form a close approximation
to a straight line between two given points.
It is commonly used to draw lines on a computer screen, as it uses only integer
addition, subtraction and bit shifting, all of which are very cheap operations
in standard computer architectures.
It is one of the earliest algorithms developed in the field of computer graphics.
A minor extension to the original algorithm also deals with drawing circles.

High level style in javascript.

Opinions are like assholes, every one has got one.

This one is mine.

Punctuation: who cares?

Punctuation is a bikeshed. Put your semicolons, whitespace, and commas where you like them.

@jonlabelle
jonlabelle / string-utils.js
Last active May 5, 2024 19:44
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str) {
return str.toLowerCase();
@blixt
blixt / prng.js
Last active January 14, 2024 07:01
A very simple, seedable JavaScript PRNG. NOTE: Please read comments on why this is not a good choice.
// NOTICE 2020-04-18
// Please see the comments below about why this is not a great PRNG.
// Read summary by @bryc here:
// https://github.com/bryc/code/blob/master/jshash/PRNGs.md
// Have a look at js-arbit which uses Alea:
// https://github.com/blixt/js-arbit
/**
@mmckegg
mmckegg / gist:44c31fa6c51ed15b06ad
Created August 2, 2014 03:50
observable array
var mutators = [
'fill', 'pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'
]
function ObservableArray(onChange){
var array = []
array.set = set
array.onchange = onChange
@Flafla2
Flafla2 / Perlin_Tiled.cs
Last active April 27, 2024 19:43
A slightly modified implementation of Ken Perlin's improved noise that allows for tiling the noise arbitrarily.
public class Perlin {
public int repeat;
public Perlin(int repeat = -1) {
this.repeat = repeat;
}
public double OctavePerlin(double x, double y, double z, int octaves, double persistence) {
double total = 0;
@arcollector
arcollector / gist:a7a1492689dee2e947ec
Last active November 21, 2023 01:34
Polygon scanline filling in JS
var polygonFilling = function( vertices ) {
// "global" variables
var verticesCount = vertices.length,
edgesEntered,
// table cols
yMax, yMin, xInt, invNegSlope;
// *************************

here are the most useful pull streams modules

combining pull streams

a library of simple functions that will be familiar functional programmers.