Skip to content

Instantly share code, notes, and snippets.

View ncou's full-sized avatar
🪲
Catching bugs !

ncou

🪲
Catching bugs !
View GitHub Profile
@ncou
ncou / gaussianblur_filter.class.js
Created April 2, 2016 10:37 — forked from pierrickouw/gaussianblur_filter.class.js
Gaussian Blur filter for fabric.js
/**
* 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() {
@ncou
ncou / google_font_importer.php
Created April 2, 2016 11:15 — forked from PeterBooker/google_font_importer.php
Imports Google Webfonts and creates a Dropdown to select a font from.
<?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');
@ncou
ncou / interval.js
Created April 17, 2016 21:38 — forked from jasdeepkhalsa/interval.js
setTimeout and setInterval with pause and resume
// 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;
};
//JS QuickSort
Array.prototype.quickSort = function() {
var r = this;
if(this.length <= 1) {
return this;
}
var less = [], greater = [];
@ncou
ncou / mergeSort.js
Created August 23, 2016 09:53 — forked from jasondscott/mergeSort.js
JavaScript Merge Sort
//Merge Sort
Array.prototype.mergeSort = function() {
var thiz = this;
if (this.length <= 1) {
return this;
}
//split left and right
var left = [], right = [];
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);
@ncou
ncou / color.php
Created September 5, 2016 22:33
PHP: Determine the dominant color of an image
<?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++) {
@ncou
ncou / index.php
Created September 9, 2016 21:35 — forked from ziadoz/index.php
Simple PHP / jQuery CSRF Protection
<?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));
}
@ncou
ncou / dominant-color.js
Created September 10, 2016 16:12 — forked from leibovic/dominant-color.js
Dominant Color
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 = {};
@ncou
ncou / average-color.js
Created September 10, 2016 20:25 — forked from fuzzyfox/average-color.js
JavaScript: image average color
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'),