Skip to content

Instantly share code, notes, and snippets.

Jonathan Gotti malko

Block or report user

Report or block malko

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@malko
malko / urlBase64ToUint8Array.js
Created Mar 31, 2017
used in pushManager.Subscribe to correctly encode the key to a Uint8Array
View urlBase64ToUint8Array.js
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/')
;
const rawData = window.atob(base64);
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)));
}
@malko
malko / makeTemplate.js
Created Mar 21, 2017
dynamic es6 template string to template methods
View makeTemplate.js
//const tpl = makeTemplate('hello ${name}')
//const name = 'world';
//tpl({name});
const makeTemplate = (templateString) => {
return (templateData) => new Function(`{${Object.keys(templateData).join(',')}}`, 'return `' + templateString + '`')(templateData);
}
@malko
malko / notify.js
Created Mar 20, 2017
Notification api
View notify.js
const notificationGrantedPromise = () => {
if (!('Notification' in window)) {
return Promise.reject();
}
return (Notification.permission !== 'default') ? Promise.resolve(Notification.permission) : Notification.requestPermission();
};
const notify = (...args) => notificationGrantedPromise().then((permission) => permission === 'granted' ? new Notification(...args) : null);
@malko
malko / enchainProxifier.js
Created Mar 8, 2017
add a fluent interface on object with promise methods
View enchainProxifier.js
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 Feb 17, 2017
outgoing rocketchat webhook to create polls
View rocketPoll.js
/*
EXAMPLE MESSAGE
!poll question?
option 1
option 2
*/
class Script {
/**
* @params {object} request
View removeDiacritics.js
/**
* 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
Jira / Rocketchat integration
View jira-rocketchat-hook.js
/*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
Gitlab / Rocketchat intégration
View gitlab-rocketchat.hooks.js
/*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 Dec 15, 2015 — forked from mebibou/pre-commit
JSHint and JSCS pre-commit hook
View pre-commit
#!/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 Sep 21, 2015 — 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
View date-functions.js
/*
* 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
You can’t perform that action at this time.