Skip to content

Instantly share code, notes, and snippets.

View markbiek's full-sized avatar

Mark Biek markbiek

View GitHub Profile
@markbiek
markbiek / jquery-canvasAnimate.js
Created July 15, 2011 16:19
jQuery Plugin to animate a series of images using the HTML canvas element
(function( $ ){
$.fn.canvasAnimate = function(options) {
return this.each( function() {
Number.prototype.zeroPad = function() {
var i = this;
if(i < 10) {
return '0000'+i;
}else if(i >= 10 && i < 100) {
return '000'+i;
}else if(i >= 100 && i < 1000) {
@markbiek
markbiek / sierpinski.html
Created August 16, 2011 16:44
Sierpinski Triangle on HTML5 canvas using chaos game rules
<canvas id="canvas" width="640" height="480">
<p>Your browser doesn't support canvas.</p>
</canvas>
@markbiek
markbiek / Improved setPixel
Created January 16, 2012 16:31
An improved setPixel function for drawing on a canvas (allows color to be specified using HTML hex codes)
Object.prototype.setPixel = function(point, rgba) {
if(!this.hasOwnProperty('data')) {
throw'This method only works with ImageData objects created with createImageData';
}
var imageData = this;
if(typeof rgba == 'string') {
var useDefault = true; //If anything is wrong with the hex code, fall back to a default color
var matches;
@markbiek
markbiek / jquery-custom-events.js
Created November 1, 2012 16:49
Stupid simple example of jQuery custom events
/*
Fiddle: http://jsfiddle.net/SBp85/18/
Markup:
<p><a href="#" id="button"><img src="http://placekitten.com/64/64" alt="Click" /></a></p>
<div id="console"></div>
*/
@markbiek
markbiek / Object.prototype.extend
Created August 7, 2013 19:02
Simple Javascript function to populate an object with the properties of another. Doesn't take deep objects into account.
if(!Object.hasOwnProperty('extend')) {
Object.prototype.extend = function(obj) {
for(var i in obj) {
if(obj.hasOwnProperty(i) && !this.hasOwnProperty(i)) {
this[i] = obj[i];
}
}
};
}
@markbiek
markbiek / binarysearch.js
Created August 23, 2013 14:42
Javascript recursive binary search
Object.prototype.bsearch = function(i, min, max) {
//console.log('Finding ' + i + ' out of ' + this.length + ' items');
if(max < min) {
return 0;
}else {
var mid = Math.floor((min + max) / 2);
//console.log('Midpoint of ' + min + '->' + max + ' is ' + mid);
if(this[mid] > i) {
@markbiek
markbiek / pycheck.sh
Created March 3, 2014 14:34
Python script syntax checker
#!/bin/bash
if [ -f $1 ]
then
python -c "compile(open('$1').read(), '$1', 'exec')"
else
echo "The file $1 was not found."
exit 1
fi
### Keybase proof
I hereby claim:
* I am markbiek on github.
* I am antelopelovefan (https://keybase.io/antelopelovefan) on keybase.
* I have a public key whose fingerprint is E0CA 9E6A 5AE8 FD26 C8BA 58FB B196 5A58 A94D 9A8C
To claim this, I am signing this object:
@markbiek
markbiek / gist:5a811f695fa0a7189a20
Last active August 29, 2015 14:15
ConcurrentQueue<T> example
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections.Concurrent;
using System.Threading;

Keybase proof

I hereby claim:

  • I am markbiek on github.
  • I am antelopelovefan (https://keybase.io/antelopelovefan) on keybase.
  • I have a public key whose fingerprint is 27F1 D1A4 91D7 7E39 B9B3 9597 4501 79A1 C9C1 051F

To claim this, I am signing this object: