Skip to content

Instantly share code, notes, and snippets.

View malko's full-sized avatar

Jonathan Gotti malko

View GitHub Profile
@malko
malko / enchainProxifier.js
Created March 8, 2017 13:33
add a fluent interface on object with promise methods
const enchainProxifier = (target, promise = Promise.resolve()) => {
return new Proxy(target, {
get(target, propName) {
if (propName === 'promise') {
return promise;
} else if (propName === 'then') {
return (...args) => promise.then(...args);
}
if (target[propName] instanceof Function) {
return (...args) => enchainProxifier(target, promise.then(() => target[propName](...args)));
@malko
malko / rocketPoll.js
Last active February 17, 2017 14:41
outgoing rocketchat webhook to create polls
/*
EXAMPLE MESSAGE
!poll question?
option 1
option 2
*/
class Script {
/**
* @params {object} request
/**
* source: http://stackoverflow.com/a/37511463/646056
*/
function removeDiacritics(s) {
return s.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
@malko
malko / jira-rocketchat-hook.js
Created May 10, 2016 15:26
Jira / Rocketchat integration
/*jshint esnext:true*/
const DESC_MAX_LENGTH = 140;
const JIRA_LOGO = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAACRElEQVRYhbWXsUscQRTGf4iIyHHIISIWIsHisMgfkNIiBJFwiKQIkipVqpA/wEZEggSxEkmZwiKI5A84REKKkIMQrINYBQmHBDmEHJdNMW+42dk3d3O76wcDu2/e973vZvfN7EF+PAfaMjYL6AzFJFBRYh0gkdEBpryciuQVwjPgFugCu068CvQcAz1g2pnfEc6taOTGL6dIAjxw5nad+FsnvuhxrosYuPbElrz5Rc8Ucu9yfhcxsAncYZZ4fwTeO+HcUcILWgFqOXg1si9vFBrAXB7iEMySfYQZzGCeWxdoAq+Bh8BYjoJjwn0jWrYrqsOIbdIvUQLseTmPgHXgiYx1ibnYU3RuYpyfKMQ/mNWx+KzkfHHmZ4Tj55zGGNhQiAlw5OQ8VeYbzvxRQCNqUxoHLgMCa07eRyd+4sTXAtwrYCLGAJje1URugLrkVIHvMuyLVZccjfsitrhFMyD0k36bTtA/cOZkTuOckaOTFtA7IgEuSG9ONeBHILctWrnwGNO/mvA3zAk4LddaThfTpoXwKiBuVyL0yxPhloLtAUVCY7us4hb7IxQ/KLu4xWFE8cP7Kg6mld4PKH5BvoNrZBMfBphohKnFMAusyvU48ClgoA3M34eBUynwUu6ngK8BE1Gn3ihYccR79Jd5nuyXsx0rZRo498Q7mK8dMDudZuC8rOLLgQI7Ts5xIGe5DANbinCP9AfmEul/SnZslWHgTBFuKnna8a3lpRCzadSVWMiAj6GPIMbAX+/+H9BS8loyN4ibwX9j/jIXDkk+pgAAAABJRU5ErkJggg==';
function stripDesc(str) {
return str.length > DESC_MAX_LENGTH ? str.slice(
@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);