Skip to content

Instantly share code, notes, and snippets.

View johnatandias's full-sized avatar
👨‍👩‍👧‍👦
No success compensates for your family's failure.

Johnatan Dias johnatandias

👨‍👩‍👧‍👦
No success compensates for your family's failure.
View GitHub Profile
@johnatandias
johnatandias / dependencies.js
Created August 4, 2020 14:12
Check if dependencies need updating
const request = require('request');
const fs = require('fs');
const package = require('./package.json');
const dependencies = {
...package.dependencies,
...package.devDependencies,
};
const getLastVersionOfPackage = packageName => new Promise((resolve, reject) => {
@johnatandias
johnatandias / advanceTimersByTime.test.tsx
Created October 20, 2020 15:26
Advance Timers By Time
describe('description', () => {
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.runOnlyPendingTimers();
jest.useRealTimers();
});
@johnatandias
johnatandias / msToTime.js
Last active November 30, 2020 19:40
Convert Milliseconds to Hours
function msToTime(duration = 0) {
const seconds = `0${Math.floor((duration / 1000) % 60)}`.slice(-2)
const minutes = `0${Math.floor((duration / (1000 * 60)) % 60)}`.slice(-2)
const hours = `0${Math.floor((duration / (1000 * 60 * 60)) % 24)}`.slice(-2)
return `${hours}:${minutes}:${seconds}`;
}
console.log(msToTime(97739)) // 00:01:37
@johnatandias
johnatandias / camelToSnakeCase.test.ts
Created February 26, 2021 13:45
Snake case <-> Camal case
import { camelToSnakeCase, camelKeyToSnakeCase } from './camelToSnakeCase'
describe('camel to snake case', () => {
describe('camelToSnakeCase', () => {
it('should be convert camel case to snake case ', () => {
expect(camelToSnakeCase('camelToSnakeCase')).toBe('camel_to_snake_case')
})
it('must return an argument value when it is not a valid string', () => {
// @ts-ignore
@johnatandias
johnatandias / formatToPattern.ts
Last active March 1, 2021 19:33
Format value to pattern
const formatToPattern = (value: string, pattern: string): string => {
const maskLength = [...pattern.matchAll(/#/g)].length
if (maskLength !== value.length) return value
let i = 0
return pattern.replace(/#/g, () => value[i++])
}
console.log(formatToPattern('99999999999', '(##) #####-####')) // (99) 99999-9999
console.log(formatToPattern('12345678989', '###.###.###-##')) // 123.456.789-89
@johnatandias
johnatandias / videoSpeed.js
Created March 15, 2021 01:57
Change video speed
const video = document.querySelector('video')
video.defaultPlaybackRate = 1.5
video.playbackRate = 1.5

[app] can't be opened because Apple cannot check it for malicious software

Run

xattr -rd com.apple.quarantine [path-to-your-app]

After run application

xattr -l [path-to-your-app]
@johnatandias
johnatandias / index.html
Last active April 29, 2022 18:11
Web Crypto API
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>
const encodeData = () => {
const longJson = JSON.stringify([{