Skip to content

Instantly share code, notes, and snippets.

View gugadev's full-sized avatar
🌐
Web & Mobile

Gustavo García gugadev

🌐
Web & Mobile
View GitHub Profile
@gugadev
gugadev / environment.ts
Created May 13, 2021 16:22
Utilitary for get environment variables in CRA.
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 / flutter-setup-windows-guide.md
Created June 13, 2021 19:10
Guide to setup flutter and android on Windows 10

Flutter setup Windows guide

No requires Android Studio 🥳



@gugadev
gugadev / next.config.js
Created October 29, 2021 15:57 — forked from skolhustick/next.config.js
next-js-pwa-setup
const withPWA = require('next-pwa')
module.exports = withPWA({
pwa: {
dest: 'public'
}
})
@gugadev
gugadev / gen_random_alphanum.dart
Created January 16, 2022 16:48
Create random alphanumeric string
/// 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 / main.dart
Created January 25, 2022 14:03
Generate random alphanumeric password
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 / main.dart
Created January 25, 2022 14:03
Migration from OutlineButton to OutlinedButton.
import 'package:flutter/material.dart';
enum DialogButtonStyle {
PRIMARY,
SECONDARY,
}
void main() {
runApp(App());
}
@gugadev
gugadev / legacy.json
Created January 25, 2022 18:33
Migration of the REST payload from legacy to v1 - FCM
{
"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 / build-sw.js
Last active April 9, 2022 22:47
Service worker examples in TypeScript and JavaScript
/**
* * 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 / sw-service.ts
Last active April 12, 2022 04:17
Vanilla Service Worker
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 / tw-unfollower.js
Created December 9, 2022 00:10
Tiny script to unfollow all people you're following. Just go to https://twitter.com/<youruser>/following, open the console and run the code (testing in responsive mode).
function unfollow() {
let count = 0
const buttons = document.querySelectorAll('[data-testid*="-unfollow"]')
if (!buttons.length) {
console.log(`${count} People unfollowed`)
return
}
const waitFor = (ms) => new Promise(resolve => setTimeout(resolve, ms))