Skip to content

Instantly share code, notes, and snippets.

View malko's full-sized avatar

Jonathan Gotti malko

View GitHub Profile
@malko
malko / gitlab-rocketchat.hooks.js
Last active May 25, 2018 08:07
Gitlab / Rocketchat intégration
/*jshint esnext:true*/
// see https://gitlab.com/help/web_hooks/web_hooks for full json posted by GitLab
const NOTIF_COLOR = '#6498CC';
const refParser = (ref) => ref.replace(/^.*?([^\/]+)$/,'$1');
class Script {
process_incoming_request({request}) {
try {
switch(request.headers['x-gitlab-event']){
case 'Push Hook':
@malko
malko / pre-commit
Last active December 15, 2015 14:52 — forked from mebibou/pre-commit
JSHint and JSCS pre-commit hook
#!/bin/sh
# pre-commit git hook.
files=$(git diff --cached --name-only --diff-filter=ACMR -- \*.js **/*.js)
pass=true
errorJscs=0
errorJshint=0
if [ "$files" != "" ]; then
@malko
malko / date-functions.js
Last active September 21, 2015 16:25 — forked from kmturley/data-functions.js
Re-written date functions to not use eval() original gist https://gist.github.com/xaprb/8492729 modified by @kmturley
/*
* Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, version 2.1.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
/**
Tim Down reply at
http://stackoverflow.com/questions/6690752/insert-html-at-caret-in-a-contenteditable-div/6691294#6691294
*/
function pasteHtmlAtCaret(html) {
var sel, range;
if (window.getSelection) {
// IE9 and non-IE
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
@malko
malko / gist:ea530a66b5927ea03d5c
Created February 23, 2015 13:37
Confluence fancybox enhance navigation
// ==UserScript==
// @name Confluence fancybox enhance navigation
// @version 0.0.1
// @description add navigation through image previews
// @author Jonathan Gotti
// @match http://*/*
// @match https://*/*
// ==/UserScript==
// update match rules for your domain
(function(){
@malko
malko / parseBindingAttr
Created February 2, 2015 16:59
parseBindingAttr for angular
/** By J.louis */
function parseExprAttr($parse, $scope, $attrs, name) {
var fn = $parse($attrs[name]),
res
;
res = function (locals) {
return fn($scope, locals);
};
res.assign = fn.assign && function (value) {
fn.assign($scope, value);
@malko
malko / propertyComparator.js
Last active July 19, 2017 13:01
make a multiple fields comparator for sort functions
/**
* return a comparator to use in Array.sort method context.
* take a list of properties (array or string delimited by pipe or comma) which you want to use for sort
* @param {(string|string[])) fields list of properties names (array or string delimited by pipe or comma) which you want to use for sort
* each field name may be prefixed by an < or > to sort on ascending or descending order
* you can use n< or n> as prefix for a natural order sorting
* @returns {function(object, object)}
*/
function propertyComparator(compareConfig) {
if (typeof compareConfig === 'string') {
@malko
malko / gist:c5403a9312e0ffe98fbb
Created August 12, 2014 09:49
shortest cross platform onReady document
/**
* very poor (but short and easy) cross platform implementation to detect dom readiness
*/
function onReady(fn){
document.body ? fn() : setTimeout(function(){ onReady(fn);},50);
};
@malko
malko / npmMonthlyStats.js
Created February 4, 2014 13:33
get monthly npm statistics for given package name
function npmMonthlyStats(pkgName){
var xhr=new XMLHttpRequest()
, rows
, obj={}
;
xhr.open('GET','https://isaacs.iriscouch.com/downloads/_design/app/_view/pkg?group_level=2&start_key=%5B%22' + pkgName + '%22%5D&end_key=%5B%22' + pkgName + '%22,%7B%7D%5D', false);
xhr.send();
rows=JSON.parse(xhr.responseText).rows;
rows.forEach(function(v,k){
var d = v.key[1].slice(0,7);
@malko
malko / report
Created December 5, 2013 00:33
still failing test
60 failing
1) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a thenable `y` is a thenable that tries to fulfill twice for an asynchronously-fulfilled custom thenable `then` calls `resolvePromise` synchronously via return from a fulfilled promise:
Error: timeout of 200ms exceeded
at null.<anonymous> (/tmp/D.js/node_modules/promises-aplus-tests/node_modules/mocha/lib/runnable.js:165:14)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
2) 2.3.3: Otherwise, if `x` is an object or function, 2.3.3.3: If `then` is a function, call it with `x` as `this`, first argument `resolvePromise`, and second argument `rejectPromise` 2.3.3.3.1: If/when `resolvePromise` is called with value `y`, run `[[Resolve]](promise, y)` `y` is a thenable for a then