Skip to content

Instantly share code, notes, and snippets.

View jonasraoni's full-sized avatar
☠️
Do what you want cause a pirate is free! You are a pirate!

Jonas Raoni Soares da Silva jonasraoni

☠️
Do what you want cause a pirate is free! You are a pirate!
View GitHub Profile
@jonasraoni
jonasraoni / .npmrc
Created August 16, 2019 08:54
Example of configuration to make yarn use many registries with authentication
registry=https://artifactory.example.com/api/npm/proxy_of_npm/
//artifactory.example.com/api/npm/proxy_of_npm/:_authToken=SUPER_SECRET_KEY
//artifactory.example.com/api/npm/proxy_of_npm/:always-auth=true
//artifactory.example.com/api/npm/YOUR_PERSONAL_REPOSITORY/:_authToken=SUPER_SECRET_KEY
//artifactory.example.com/api/npm/YOUR_PERSONAL_REPOSITORY/:always-auth=true
@jonasraoni
jonasraoni / format-currency.js
Created August 7, 2019 12:40
Format currency
'1234567890.123'.replace(/\d(?=(\d{3})+(?:$|\.))/g, '$& ');
@jonasraoni
jonasraoni / vue-directive-get-set-v-model.js
Created August 7, 2019 07:21
Get/set v-model value inside an Vue directive
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
// NOTES:
// 1. The vnode is provided by the directive callbacks
// 2. If eval sounds scary to you, you might replace it by any function that provides "navigation" from a string like "array[0].property" (that's what you get from the "expression") =]
getValue (vnode) {
//standard v-model
if (vnode.data.model) {
@jonasraoni
jonasraoni / list-to-tree.js
Created July 5, 2019 13:34
Performatic list to tree using one loop and map
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
function tree(items) {
const tree = [];
const map = new Map;
for (const item of items) {
const placeholder = map.get(item.id);
item.children = placeholder ? placeholder.children : [];
map.set(item.id, item);
@jonasraoni
jonasraoni / regexp-quote.js
Created April 2, 2019 19:11
Regexp match quotes
/(["'`])(?:\\.|(?!\1).)*?\1/
@jonasraoni
jonasraoni / hub.js
Created March 30, 2019 19:43
Class to handle SignalR subscriptions
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
const signalR = require('@aspnet/signalR');
export default class Hub {
constructor (url, autoReloadTimeout = 1000) {
Object.assign(this, {
url,
autoReloadTimeout,
@jonasraoni
jonasraoni / server-time.vue
Created March 30, 2019 19:41
Vue plugin to retrieve the server time
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
export default class ServerTime {
constructor ({http = new Error('http parameter is required'), url = new Error('url is required'), thresholdDelay = 300, autoSynchronizeProbes = 0}) {
Object.assign(this, {
http,
url,
thresholdDelay,
best: null
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
export default function debounce (action, delay) {
let handle;
return function (...args) {
if (handle) {
clearTimeout(handle);
handle = null;
}
@jonasraoni
jonasraoni / max-decimal-places.js
Created March 30, 2019 19:38
Given a list of numeric arguments, retrieves the longest amount of decimal places, useful to format :)
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
export default (...values) => Math.max(...values.map(value =>
(value = (value + '').split(/[.,]/)).length > 1 && value.pop().length
));
@jonasraoni
jonasraoni / backup.js
Last active February 27, 2019 13:03
Creates a full backup of all SQL Server, PostgreSQL and MySQL databases in JScript/JavaScript.
Backup = {
shell: WScript.CreateObject("WScript.Shell"),
base: "C:/BACKUP/",
username: "USERNAME",
hostname: "HOST",
password: "PASSWORD",
type: {
postgreSQL: function(){
var shell = Backup.shell;
var path = "c:/program files/postgresql/9.6/bin/";