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 / js-ajax-php-json-return.html
Created September 12, 2016 21:29 — forked from jonsuh/js-ajax-php-json-return.html
jQuery AJAX Call to PHP Script with JSON Return
<div class="the-return">
[HTML is replaced when successful.]
</div>
@ncou
ncou / simple-json-reponse.php
Created September 12, 2016 21:31 — forked from james2doyle/simple-json-reponse.php
A simple JSON response function for PHP. Used in various PhileCMS plugins.
<?php
function json_response($message = null, $code = 200)
{
// clear the old headers
header_remove();
// set the actual code
http_response_code($code);
// set the header to make sure cache is forced
header("Cache-Control: no-transform,public,max-age=300,s-maxage=900");
<?php
$data = (object)array(
"html" => "<foo bar=\"baz\"/> &amp;",
"arabic" => "العربية al-ʿarabiyyah, IPA: [æl ʕɑrɑˈbijjɐ], or عربي ʿarabī",
"hebrew" => "עִבְרִית, Ivrit",
"chinese" => "汉语/漢語 Hanyu; 华语/華語 Huáyǔ; 中文 Zhōngwén",
"korean" => "한국어/조선말",
"japanese" => "日本語 Nihongo",
"umlauts" => "äüöãáàß",
@ncou
ncou / Difference between debounce and throttle.md
Created September 13, 2016 21:14 — forked from makenova/Difference between debounce and throttle.md
Javascript function debounce and throttle

Difference between Debounce and Throttle

Debounce

Debounce a function when you want it to execute only once after a defined interval of time. If the event occurs multiple times within the interval, the interval is reset each time.
Example A user is typing into an input field and you want to execute a function, such as a call to the server, only when the user stops typing for a certain interval, such as 500ms.

Throttle

@ncou
ncou / imagick_average_colour.php
Created September 30, 2016 14:42 — forked from paulferrett/imagick_average_colour.php
This function will get the average colour of an image file using PHP and Image Magick using the IMagick extension.
<?php
/**
* Get the average pixel colour from the given file using Image Magick
*
* @param string $filename
* @param bool $as_hex Set to true, the function will return the 6 character HEX value of the colour.
* If false, an array will be returned with r, g, b components.
*/
function get_average_colour($filename, $as_hex_string = true) {
@ncou
ncou / fabricBezierCurve.js
Created November 1, 2016 06:07 — forked from paulkaplan/fabricBezierCurve.js
Cubic bezier curves with fabric.js renderer
var CubicBezier = function(canvas, opts){
if(!opts) opts = {};
this.start = opts.start || new Vec2(100,100);
this.end = opts.end || new Vec2(400, 400);
this.c1 = opts.c1 || new Vec2(100, 300);
this.c2 = opts.c2 || new Vec2(300, 100);
this.curve = new fabric.Path( this.toSVGPath() );
@ncou
ncou / ._window-focus-blur.md
Created November 1, 2016 09:47 — forked from RunnerRick/._window-focus-blur.md
Demonstrates how to handle the window's `focus` and `blur` events.

Demonstrates how to handle the window's focus and blur events.

This code does not depend on any third-party libraries like jQuery.

@ncou
ncou / relativeLuminanceW3C.js
Created November 6, 2016 10:48 — forked from jfsiii/relativeLuminanceW3C.js
Calculate the relative luminance, or brightness, of a color. Accepts values 0-255 for R, G, B.
// from http://www.w3.org/TR/WCAG20/#relativeluminancedef
function relativeLuminanceW3C(R8bit, G8bit, B8bit) {
var RsRGB = R8bit/255;
var GsRGB = G8bit/255;
var BsRGB = B8bit/255;
var R = (RsRGB <= 0.03928) ? RsRGB/12.92 : Math.pow((RsRGB+0.055)/1.055, 2.4);
var G = (GsRGB <= 0.03928) ? GsRGB/12.92 : Math.pow((GsRGB+0.055)/1.055, 2.4);
var B = (BsRGB <= 0.03928) ? BsRGB/12.92 : Math.pow((BsRGB+0.055)/1.055, 2.4);
@ncou
ncou / relativelumance.js
Created November 6, 2016 10:50 — forked from jfsiii/relativelumance.js
Relative Luminance from RGB color.
// from http://en.wikipedia.org/wiki/Luminance_(relative)
// R, G, B are integers between 0 and 255
function relativeLuminance(R, G, B) {
var Y = (0.2126 * R + 0.7152 * G + 0.0722 * B) / 255;
return Y;
}
@ncou
ncou / colours.js
Created November 6, 2016 10:50 — forked from leocaseiro/colours.js
Javascript parse colours (Hex to RGB and vice versa) as well as luminance(dark or bright)
/**
* Original code from https://github.com/mike-schultz/materialette
*/
function rgbToHex(r, g, b) {
return "#" + ((1 << 24) + (parseInt(r) << 16) + (parseInt(g) << 8) + parseInt(b)).toString(16).slice(1);
}
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);