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
View debounce.js
//+ 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 Mar 30, 2019
Given a list of numeric arguments, retrieves the longest amount of decimal places, useful to format :)
View max-decimal-places.js
//+ 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 / number-to-ordinal.js
Created Feb 24, 2019
Number to ordinal (English)
View number-to-ordinal.js
function numberToOrdinal(n) {
const
number = Math.abs(n) || 0,
units = number % 10,
tens = ~~(number % 100 / 10),
suffix = new Map([
[1, 'st'],
[2, 'nd'],
[3, 'rd']
]);
@jonasraoni
jonasraoni / update.sql
Last active Feb 24, 2019
Fill the gaps in SQL Server
View update.sql
/*
There is a table in database. This table contains unduplicated natural numbers. There may be gaps in the sequence of natural numbers in the table. You need to output missing numbers.
Table of natural numbers: declare @values as table ([number] int not null).
Test data: insert into @values([number]) values (1), (2), (3), (5), (9).
Result: declare @missing as table ([left] int not null, [right] int not null).
*/
DECLARE @values AS TABLE ([number] INT NOT NULL);
INSERT INTO @values([number]) VALUES (1), (2), (3), (5), (9);
DECLARE @missing AS TABLE ([left] INT NOT NULL, [right] INT NOT NULL)
@jonasraoni
jonasraoni / Flattener.cs
Created Jul 14, 2018
Flatten Array in C#
View Flattener.cs
using System;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Extends the Array with the Flatten method
/// </summary>
public static class Flattener {
/// <summary>
/// Given a N-dimensional array, flattens it into a new one-dimensional array without modifying the elements' order
@jonasraoni
jonasraoni / cloudSettings
Last active Oct 8, 2021
Visual Studio Code Settings Sync Gist
View cloudSettings
{"lastUpload":"2021-10-08T12:18:16.362Z","extensionVersion":"v3.4.3"}
@jonasraoni
jonasraoni / cross-query.sql
Created May 10, 2018
Microsoft SQL Server Management Studio: Add external server and query against local databases.
View cross-query.sql
EXEC sp_addlinkedserver @server='SERVER_ADDRESS';
EXEC sp_addlinkedsrvlogin @rmtsrvname='SERVER_ADDRESS',@useself=false, @rmtuser='USER', @rmtpassword='PASSWORD';
--------------
INSERT INTO LOCAL_TABLE
SELECT *
FROM
[SERVER_ADDRESS].DATABASE.dbo.REMOTE_TABLE
View keybase.md

Keybase proof

I hereby claim:

  • I am jonasraoni on github.
  • I am jonasraoni (https://keybase.io/jonasraoni) on keybase.
  • I have a public key whose fingerprint is C6B8 2A63 2F58 4784 159E 802F 5ECC 07E6 0269 4752

To claim this, I am signing this object:

View twin-strings.cs
/*
Twin Strings
Two strings, a and b, are said to be twins only if they can be made equivalent by performing some number of operations on one or both strings. There are two possible operations:
SwapEven: Swap a character at an even-numbered index with a character at another even-numbered index.
SwapOdd: Swap a character at an odd-numbered index with a character at another odd-numbered index.
For example, a = "abcd" and b = "cdab" are twins because we can make them equivalent by performing operations. Alternatively, a = "abcd" and b = "bcda" are not twins (operations do not move characters between odd and even indices), and neither are a = "abc" and b = "ab" (no amount of operations will insert a 'c' into string b).
Complete the twins function in the provided code. It has two parameters:
@jonasraoni
jonasraoni / Extends.cs
Created Nov 4, 2017
Some C# extensions.
View Extends.cs
using System;
using System.IO;
using System.Web;
using System.Text;
using System.Collections.Generic;
using System.Collections;
namespace Raoni {
public delegate bool Generator<T>(out T value);
public delegate bool Enumerator<T>(T value);