Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Gustavo García gugadev

🎯
Focusing
View GitHub Profile
@gugadev
gugadev / sw-service.ts
Last active Apr 12, 2022
Vanilla Service Worker
View sw-service.ts
export function register() {
if ("serviceWorker" in navigator) {
return new Promise((resolve) => {
navigator.serviceWorker.register("/sw.js")
.then((registration) => {
registration.onupdatefound = () => {
const worker = registration.active;
if (worker == null) {
return;
}
@gugadev
gugadev / build-sw.js
Last active Apr 9, 2022
Service worker examples in TypeScript and JavaScript
View build-sw.js
/**
* * This is not in use.
* * Para conocimiento general:
* Esta es una forma de generar el "precache manifest"
* de un service worker. La otra forma es como se detalla
* en el script de NPM "sw" en el presente package.json.
*/
const workboxBuild = require("workbox-build");
const buildServiceWorker = () => {
@gugadev
gugadev / legacy.json
Created Jan 25, 2022
Migration of the REST payload from legacy to v1 - FCM
View legacy.json
{
"to": "token o topic",
"priority": "high",
"notification": {
"title": "Title of the notification",
"body": "Description of the notification",
"android_channel_id": "Android channel"
},
"data": {
@gugadev
gugadev / main.dart
Created Jan 25, 2022
Migration from OutlineButton to OutlinedButton.
View main.dart
import 'package:flutter/material.dart';
enum DialogButtonStyle {
PRIMARY,
SECONDARY,
}
void main() {
runApp(App());
}
@gugadev
gugadev / main.dart
Created Jan 25, 2022
Generate random alphanumeric password
View main.dart
import 'dart:math';
void main() async {
var pwd = await getRandomPwd(8);
print(pwd);
}
Future<String> getRandomPwd(int length) async {
if (length > 62) {
throw Error('The max length of the password could be 62');
@gugadev
gugadev / gen_random_alphanum.dart
Created Jan 16, 2022
Create random alphanumeric string
View gen_random_alphanum.dart
/// Courtesy of https://stackoverflow.com/a/61929967/10670707
Future<String> genRandomAlphanumeric(int length) async {
const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
Random _rnd = Random();
return String.fromCharCodes(
Iterable.generate(
length,
(_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))
)
);
@gugadev
gugadev / next.config.js
Created Oct 29, 2021 — forked from skolhustick/next.config.js
next-js-pwa-setup
View next.config.js
const withPWA = require('next-pwa')
module.exports = withPWA({
pwa: {
dest: 'public'
}
})
@gugadev
gugadev / flutter-setup-windows-guide.md
Created Jun 13, 2021
Guide to setup flutter and android on Windows 10
View flutter-setup-windows-guide.md

Flutter setup Windows guide

No requires Android Studio 🥳



@gugadev
gugadev / environment.ts
Created May 13, 2021
Utilitary for get environment variables in CRA.
View environment.ts
export class Environment {
static string(varName: string, defaultValue = ""): string {
const value = process.env[`REACT_APP_${varName}`];
return value ?? defaultValue;
}
static int(varName: string, defaultValue = 0): number {
const value = process.env[`REACT_APP_${varName}`];
if (value) {
return Number.parseInt(value, 10);
@gugadev
gugadev / readme.md
Created Nov 30, 2020
How to use Sonarlint with your cloud configuration
View readme.md

Sonarlint y Code

Instalar Sonarlint

Lo primero es instalar la extensión Sonarlint en nuestro Code.

Crear un token