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 / Extends.cs
Created November 4, 2017 09:58
Some C# extensions.
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);
@jonasraoni
jonasraoni / twin-strings.cs
Last active February 24, 2019 11:58
Twin Strings
/*
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:

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:

@jonasraoni
jonasraoni / cross-query.sql
Created May 10, 2018 18:12
Microsoft SQL Server Management Studio: Add external server and query against local databases.
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
@jonasraoni
jonasraoni / cloudSettings
Last active November 2, 2021 08:34
Visual Studio Code Settings Sync Gist
{"lastUpload":"2021-11-02T08:34:50.367Z","extensionVersion":"v3.4.3"}
@jonasraoni
jonasraoni / Flattener.cs
Created July 14, 2018 14:46
Flatten Array in C#
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 / update.sql
Last active February 24, 2019 11:28
Fill the gaps in SQL Server
/*
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 / number-to-ordinal.js
Created February 24, 2019 11:41
Number to ordinal (English)
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 / 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
));
//+ Jonas Raoni Soares Silva
//@ http://raoni.org
export default function debounce (action, delay) {
let handle;
return function (...args) {
if (handle) {
clearTimeout(handle);
handle = null;
}