Skip to content

Instantly share code, notes, and snippets.

View acjr1910's full-sized avatar
🏠
Working from home

Agnaldo Cardoso Junior acjr1910

🏠
Working from home
View GitHub Profile
@acjr1910
acjr1910 / SomeTest.ts
Created July 23, 2023 16:09 — forked from damonbauer/SomeTest.ts
react-native-blob-util mock
import ReactNativeBlobUtil from 'react-native-blob-util';
describe('SomeTest', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('handles errors', () => {
ReactNativeBlobUtil.config.mockReturnValueOnce({
fetch: jest.fn().mockReturnValue({
@acjr1910
acjr1910 / async-chunk.js
Created June 29, 2022 11:33
split async value
/**
* custom wrapper for AsyncStorage that splits the data of a given storageKey to smaller chunks
* a large object with multiple keys will be spreaded to all the keys in the first level of the main object
* { data: { key1: value1, key2: value2, ...} }
* will be saved as key1 => value1, key2 => value2, ...
* this approach is intended to prevent the limitation of 2MB per value of AsyncStorage by spreading the values across the storage
*
* basic usage:
*
* import AsyncStorage from '@react-native-community/async-storage';
const isValidRange = (arr) => {
let previous = null;
const isLessThanPrevious = (curr) => {
if (previous == null) {
previous = curr;
return true;
}
if (previous - 1 == curr) {
previous = curr;
@acjr1910
acjr1910 / keybase.md
Created December 27, 2021 17:29
keybase.md

Keybase proof

I hereby claim:

  • I am acjr1910 on github.
  • I am acjr1910 (https://keybase.io/acjr1910) on keybase.
  • I have a public key ASAiUI2qF3OHVSozGU-9aQ2-bhlmdv7D2ouGnHz0Tbzk8Ao

To claim this, I am signing this object:

@acjr1910
acjr1910 / sample.js
Created December 21, 2021 12:42
sample
const obj = {
total_history: {
current_balance: 90,
funds: [
{
uuid: 'abd16f0a-9ae4-11ea-ad4d-0a334120f7c0',
name: 'Front RVT FIC FI Renda Fixa',
},
],
},
@acjr1910
acjr1910 / origin-response.js
Created April 23, 2021 13:08
origin response aws
const path = require("path");
const AWS = require("aws-sdk");
const S3 = new AWS.S3({
signatureVersion: "v4",
});
const Sharp = require("sharp");
const BUCKET = "some-bucket";
const QUALITY = 75;
@acjr1910
acjr1910 / viewer-request.js
Created April 23, 2021 13:07
viewer request aws
const userAgent = require("useragent");
const path = require("path");
exports.handler = async (event, context, callback) => {
const request = event.Records[0].cf.request;
const headers = request.headers;
const userAgentString =
headers["user-agent"] && headers["user-agent"][0]
? headers["user-agent"][0].value
: null;
@acjr1910
acjr1910 / redirect-debbuger.js
Last active November 30, 2020 16:59
Opens debugger before window's redirect
window.addEventListener("beforeunload", function() { debugger; }, false)
@acjr1910
acjr1910 / eitherMonad.js
Created August 20, 2020 00:57
either-monad.js
const Right = x =>
({
chain: f => f(x),
map: f => Right(f(x)),
fold: (f, g) => g(x),
toString: () => `Right(${x})`
})
const Left = x =>
({
@acjr1910
acjr1910 / fp-lib.js
Last active August 19, 2020 23:12
fp-lib
function curry(arity, fn) {
return (function nextCurried(prevArgs) {
return function curried(nextArg) {
var args = prevArgs.concat([nextArg]);
if (args.length >= arity) {
return fn(...args);
} else {
return nextCurried(args);
}
};