Skip to content

Instantly share code, notes, and snippets.

View camille-hdl's full-sized avatar

Camille Hodoul camille-hdl

View GitHub Profile
@camille-hdl
camille-hdl / debounce.js
Last active August 29, 2015 14:01
A debounce implementation in JS, with a default wait time. Useful when listening to window resize event for instance.
/* debounce(func,context,ms) returns a function that will be called only ms millisecond after it's latest call.
context and ms are optionnal.
*/
var debounce = (function(window){
var defaultMs=300;
return function (func,context,ms){
var to;
return function(){
var args = Array.prototype.slice.call(arguments);
if(!!to) clearTimeout(to);
@camille-hdl
camille-hdl / throttle.js
Created May 16, 2014 14:06
Function throttle implementation in JS, with default parameters, using closures.
/* throttle(func,ms,context) returns a function that can't be called more than once every ms milliseconds.
context and ms parameters are optionnal.
*/
var throttle = (function(window){
var defaultMs=50;
return function (func,ms,context){
var to;
var wait=false;
return function(){
var args = Array.prototype.slice.call(arguments);
@camille-hdl
camille-hdl / find_parens_sub.js
Created July 16, 2014 18:57
Get the number of capturing parentheses of a regex pattern in Javascript
/*
It isn't a full implementation : you can't use it to search named groups or anything.
It just returns the number of capturing parentheses of the pattern passed as the 1st argument.
Usage :
find_parens_sub(/(my pattern)/i.source); // 1
Idea ? comment ? insult ? camille.hodoul [at] gmail.com or @Eartz_HC
I copied this function from http://www.opensource.apple.com/source/pcre/pcre-4.2/pcre/pcre_compile.c ,
(function() {
if(!!window.history) {
var curHash = "";
var nextIndex = 0;
var setHash = function(str, title) {
curHash = str;
window.history.replaceState({}, title, '#'+str);
};
var states = ["(>°.°)>","(^°o°)^","<(°.°<)","^(°o°^)"];
@camille-hdl
camille-hdl / es6-throttle.js
Last active September 3, 2020 09:29
Function throttling implementation in ES6
/*
http://www.es6fiddle.net/i8d8e1um/
*/
var throttle = (func,ms=50,context=window) => {
let to;
let wait=false;
return (...args) => {
let later = () => {
func.apply(context,args);
};
@camille-hdl
camille-hdl / js.stx
Last active October 20, 2022 09:22
ES6-friendly EditPlus syntax file
#TITLE=JavaScript
; JavaScript syntax file written by ES-Computing, edited by https://github.com/Eartz/ based on ECMA-262 6th Edition / Draft April 3, 2015.
; This file is required for EditPlus to run correctly.
#DELIMITER=,(){}[]-+*%/="'`~!&|<>?:;.
#QUOTATION1='
#QUOTATION2="
#QUOTATION3=`
#LINECOMMENT=//
#LINECOMMENT2=
@camille-hdl
camille-hdl / getPolygonBounds.js
Created October 21, 2015 07:08
Google maps API : get polygon bounds
/**
* Recupere les limites d'un polygone
*
* @method getPolygonBounds
* @param {Object} polygon un `polygon` gmap
* @return {Object} bounds
*/
getPolygonBounds: function(polygon) {
var paths = polygon.getPaths();
var bounds = new google.maps.LatLngBounds();
<!-- see it in action here : https://github.com/rollup/rollup-starter-code-splitting/blob/master/public/index.html -->
<!-- Browsers with dynamic import support -->
<script type="module">
window.esDynamicImport = true;
// this will throw if dynamic import is not supported
import("/js/es/entrypoint.js").then(function(m) {
// do something
});
</script>
{
"env": {
"production": {
"presets": [["@babel/preset-env", {
"targets": {
"browsers": [
">0.25%",
"not op_mini all"
]
}
import babel from "rollup-plugin-babel";
import commonjs from "rollup-plugin-commonjs";
import nodeResolve from "rollup-plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import replace from "rollup-plugin-replace";
import builtins from "rollup-plugin-node-builtins";
import globals from "rollup-plugin-node-globals";
import clear from "rollup-plugin-clear";
const outputDir = "./public/js/";