Skip to content

Instantly share code, notes, and snippets.

View Tsugami's full-sized avatar

Yslan Ramos Tsugami

  • Brazil
  • 13:36 (UTC -03:00)
View GitHub Profile
@Tsugami
Tsugami / levenshtein_distance.exs
Last active December 14, 2021 22:42
Levenshtein Distance in Elixir
defmodule LevenShteinDistance do
def compare_distance(str, ""), do: String.length(str)
def compare_distance("", str), do: String.length(str)
def compare_distance(str, str), do: 0
def compare_distance(str1, str2) do
[first1, rest1] = pattern_str(str1)
[first2, rest2] = pattern_str(str2)
defmodule AliasesRegistry do
@moduledoc false
def init do
Registry.start_link(keys: :unique, name: __MODULE__)
end
def via do
{:via, Registry, {__MODULE__, :aliases_registry}}
end
def char_to_hex(char):
return char.encode('utf-8').hex()
def string_to_hex(string):
chars = list(string)
hex_chars = map(char_to_hex, chars)
return "".join(hex_chars)
print(string_to_hex("char"))
# 63686172
const isUpper = (str) => str === str.toUpperCase();
const cloneArray = (arr) => [...arr];
const cloneAndUpdateArray = (arr, value, index) => {
const newArr = cloneArray(arr);
newArr.splice(index, 1, value);
return newArr;
};
import * as React from "react";
import { useState, useEffect } from "react";
import { render } from "react-dom";
const FULL_TEXT =
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum";
function App() {
const [currentText, setCurrentText] = useState(0);
const [acc, setAcc] = useState(FULL_TEXT);
@Tsugami
Tsugami / counter.ex
Last active June 9, 2021 03:46
Example of GenServer with Tests
defmodule Counter do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, 0, name: __MODULE__)
end
@impl true
def init(initial), do: {:ok, initial}
@Tsugami
Tsugami / remove-methods-from-interface.ts
Last active December 8, 2023 07:43
Type to remove methods from interface in Typescript
interface Base {
a: unknown;
b: unknown;
c: unknown;
foo(): unknown;
bar(): unknown;
}
type RemoveMethods<T> = { [P in keyof T as T[P] extends (...args: any) => any ? never : P]: T[P] }
export const hasBit = (bit, bitfield) => (bitfield & bit) === bit;
export const addBit = (bit, bitfield) => bitfield | bit;
export const removeBit = (bit, bitfield) => bitfield & ~bit;
export const addOrRemoveBit = (bit, bitfield) => addBit(bit, bitfield) ? removeBit(bit, bitfield) : addBit(bit, bitfield);
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" = "main" ] || [ "$branch" = "dev" ]; then
echo "You can't commit directly to the \"$branch\" branch, please checkout to a new branch before committing"
exit 1
f
@Tsugami
Tsugami / index.js
Created July 15, 2021 21:33
FIREBASE REST AUTH
const FIREBASE_API_KEY = process.env.FIREBASE_API_KEY;
const FIREBASE_EMAIL = process.env.FIREBASE_EMAIL;
const FIREBASE_PASSWORD = process.env.FIREBASE_PASSWORD;
const FIREBASE_AUTH_URL = `https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=${ FIREBASE_API_KEY }`;
const method = "POST"
const body = {
email: FIREBASE_EMAIL,
password: FIREBASE_PASSWORD,