Skip to content

Instantly share code, notes, and snippets.

View Tsugami's full-sized avatar

Yslan Ramos Tsugami

  • Brazil
  • 05:38 (UTC -03:00)
View GitHub Profile
@Tsugami
Tsugami / ShortMediaStylePagination.ts
Last active September 29, 2021 14:25
custom pagination for apollo cache
import { FieldPolicy } from '@apollo/client';
type TExistingShortMedia<TNode> = {
edges: TNode[];
_search: string;
totalCount: number;
count: number;
totalPages: number;
hasNextPage: boolean;
};
@Tsugami
Tsugami / index.html
Created September 17, 2021 23:01
chartjs testing
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
@Tsugami
Tsugami / Dockerfile
Created August 31, 2021 03:02
monorepo dockerfile
FROM node:lts as builder
ENV NODE_ENV=production
WORKDIR /app
COPY package.json /app
COPY yarn.lock /app
COPY tsconfig.base.json /app
COPY /apps /app/apps
/*
dado o seguinte cenário, um objeto que pode ter valores aninhados até 2 níveis,
deve-se remover a chave do primeiro nível se alguma das chaves aninhadas
for (undefined ou {} ou '' ou null) - 0 não conta
*/
const isObject = (v) => typeof v === 'object' && !Array.isArray(v)
const isEmptyObject = (obj) => isObject(obj) && (Object.keys(obj).length === 0)
const isNull = (v) => v === '' || v === null || v === undefined;
@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,
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
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);
@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] }
@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}