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 / tootip-on-overflow-directive.js
Created Jan 12, 2021
Vue directive: Tooltip on overflow for hidden text
View tootip-on-overflow-directive.js
export default class tooltipOnOverflowDirective {
static install (Vue) {
Vue.directive('vtb-tooltip-on-overflow', this.directive);
}
static directive = {
bind (el) {
for (const event of ['mouseover', 'mouseout']) {
if (!TooltipOnOverflowDirective.polyfilled) {
polyfill();
@jonasraoni
jonasraoni / format-number.js
Created Jan 12, 2021
Format number Vue directive
View format-number.js
export default {
install: Vue => Vue.filter('format-number', (value, { thousand = ' ', decimal = '.', decimals = null, maxDecimals = decimals, minDecimals = decimals, normalize = true, roundToEven = true } = {}) => {
value = normalize ? normalizeNumber(value) : `${value != null ? value : ''}`;
let pieces = value.split('.');
if (!pieces[0].length) {
return;
}
if (minDecimals > 0) {
pieces[1] = (pieces[1] = pieces[1] || '').padEnd(minDecimals, '0');
@jonasraoni
jonasraoni / UrlBuilder.cs
Created Dec 23, 2020
Simple URL builder for C#
View UrlBuilder.cs
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace JonasRaoni
{
@jonasraoni
jonasraoni / valid-utf-8-regexp.txt
Created Dec 6, 2020
Regular expression to find valid UTF-8 characters (useful for filtering bad input which might break some applications)
View valid-utf-8-regexp.txt
[\x00-\x7F] # ASCII
|[\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|\xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|\xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|\xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
|[\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
|\xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
@jonasraoni
jonasraoni / convert.js
Created Oct 29, 2020
Convert boolean to positive (1) negative (-1)
View convert.js
const condition = true;
// I don't know why, but adding an if here makes me sad since I started programming :L
condition ? 1 : -1;
// Alternative way 1
(-1) ** condition;
// Alternative way 2
2 * condition - 1;
@jonasraoni
jonasraoni / Lazy.php
Created Jun 10, 2020
Class to retrieve values lazily from a callback
View Lazy.php
<?php
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
class Lazy {
private $_cache;
private $_handler;
public function __construct(callable $handler)
{
@jonasraoni
jonasraoni / regexp.js
Created Jun 1, 2020
RegExp techniques to split
View regexp.js
//Split by nothing/position
'USDEUR'.split(/(?=\w{3}$)/); //["USD", "EUR"]
//Split without consuming/swallowing
'2020-10-10'.split(/(-)/); //["2020", "-", "10", "-", "10"]
@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