This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gaussian blur filter for fabricjs | |
* Example: | |
* obj.filters.push(new fabric.Image.filters.GaussianBlur(6)); | |
* obj.applyFilters(canvas.renderAll.bind(canvas)); | |
* | |
* Adapted from <a href="http://www.quasimondo.com/BoxBlurForCanvas">http://www.quasimondo.com/BoxBlurForCanvas</a> | |
*/ | |
(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Google Font Importer | |
*/ | |
$fonts = "https://www.googleapis.com/webfonts/v1/webfonts?key=AIzaSyCpfnm5kVng8hhP_jnAnnTXVP7MEUM89-k"; | |
$fonts = file_get_contents($fonts, 0, null, null); | |
$fp = fopen('fonts.txt', 'w'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/7279567/how-do-i-pause-a-window-setinterval-in-javascript | |
function RecurringTimer(callback, delay) { | |
var timerId, start, remaining = delay; | |
this.pause = function() { | |
window.clearTimeout(timerId); | |
remaining -= new Date() - start; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//JS QuickSort | |
Array.prototype.quickSort = function() { | |
var r = this; | |
if(this.length <= 1) { | |
return this; | |
} | |
var less = [], greater = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Merge Sort | |
Array.prototype.mergeSort = function() { | |
var thiz = this; | |
if (this.length <= 1) { | |
return this; | |
} | |
//split left and right | |
var left = [], right = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mergeSort(arr) { | |
for (var n = 1; n < 4 ; n++){ | |
var seg_size = Math.pow(2, n); | |
for (var seg = 0; seg < Math.ceil(arr.length/seg_size); seg++) { | |
var before = arr.slice(0, seg * seg_size); | |
var cur = arr.slice(seg * seg_size, (seg+1) * seg_size); | |
var after = arr.slice((seg+1) * seg_size); | |
var left = cur.slice(0, seg_size/2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* PHP: Determine the dominant color of an image | |
* http://www.catswhocode.com/blog/10-super-useful-php-snippets-you-probably-havent-seen | |
*/ | |
$i = imagecreatefromjpeg("image.jpg"); | |
for ($x=0;$x<imagesx($i);$x++) { | |
for ($y=0;$y<imagesy($i);$y++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// See: http://blog.ircmaxell.com/2013/02/preventing-csrf-attacks.html | |
// Start a session (which should use cookies over HTTP only). | |
session_start(); | |
// Create a new CSRF token. | |
if (! isset($_SESSION['csrf_token'])) { | |
$_SESSION['csrf_token'] = base64_encode(openssl_random_pseudo_bytes(32)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getDominantColor(aImg) { | |
let canvas = document.createElement("canvas"); | |
canvas.height = aImg.height; | |
canvas.width = aImg.width; | |
let context = canvas.getContext("2d"); | |
context.drawImage(aImg, 0, 0); | |
// keep track of how many times a color appears in the image | |
let colorCount = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getAverageColor = (function(window, document, undefined){ | |
return function(imageURL, options}){ | |
options = { | |
// image split into blocks of x pixels wide, 1 high | |
blocksize: options.blocksize || 5, | |
fallbackColor: options.fallbackColor || '#000' | |
}; | |
var img = document.createElement('img'), | |
canvas = document.createElement('canvas'), |
OlderNewer