Skip to content

Instantly share code, notes, and snippets.

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 / C# Version Cheat Sheet.md
Created May 28, 2020 — forked from Gutek/C# Version Cheat Sheet.md
Short cheat sheet of changes in C# language from version 6 to 9
View C# Version Cheat Sheet.md

CS 6

read-only auto properties

Small help with immutable types...

// private readonly int _age;
// public int Age { get { return _age; } }
public int Age { get; }
@jonasraoni
jonasraoni / vue-select-all-component.vue
Last active Apr 10, 2020
Generic component to select all checkboxes
View vue-select-all-component.vue
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
<template lang="pug">
span.field(@click.stop="")
input.is-checkradio(
v-bind="$attrs"
type="checkbox"
ref="checkbox"
:indeterminate.prop="status === null"
@jonasraoni
jonasraoni / .npmrc
Created Aug 16, 2019
Example of configuration to make yarn use many registries with authentication
View .npmrc
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
View format-currency.js
'1234567890.123'.replace(/\d(?=(\d{3})+(?:$|\.))/g, '$& ');
@jonasraoni
jonasraoni / vue-numeric-directive.js
Last active Aug 5, 2021
Numeric directive for Vue, v-decimal and v-integer, with unsigned modifier
View vue-numeric-directive.js
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
export default class NumericDirective {
constructor (input, binding) {
Object.assign(this, { input, binding });
input.addEventListener('keydown', this);
input.addEventListener('change', this);
}
@jonasraoni
jonasraoni / vue-directive-get-set-v-model.js
Created Aug 7, 2019
Get/set v-model value inside an Vue directive
View vue-directive-get-set-v-model.js
//+ 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 Jul 5, 2019
Performatic list to tree using one loop and map
View list-to-tree.js
//+ 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);
View regexp-quote.js
/(["'`])(?:\\.|(?!\1).)*?\1/
@jonasraoni
jonasraoni / hub.js
Created Mar 30, 2019
Class to handle SignalR subscriptions
View hub.js
//+ 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 Mar 30, 2019
Vue plugin to retrieve the server time
View server-time.vue
//+ 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