Skip to content

Instantly share code, notes, and snippets.

@ivanfgm
ivanfgm / firebaseAdmin.js
Created March 17, 2022 20:56
Use Firebase Admin SDK inside a Next.js project.
// I usually put this in config/firebaseAdmin.js
import * as admin from 'firebase-admin'
// You need your account service key json file inlined in .env
let serviceAccount = JSON.parse(process.env.FIREBASE_ACCOUNTKEY)
let config = {
credential: admin.credential.cert(serviceAccount)
}
export default !admin.apps.length ? admin.initializeApp(config) : admin;
@ivanfgm
ivanfgm / cf7-recaptcha-v3.php
Created June 1, 2021 20:40
Validate a recaptcha token with wordpress plugin contact form 7, useful when integrating with a custom frontend.
<?php
/* Verificacion especial recaptcha - cf7 */
add_filter('wpcf7_spam', function ($spam) {
if ($spam) {
return $spam;
}
@ivanfgm
ivanfgm / launch.json
Created February 10, 2021 02:56
VSCode's launch.json for Next.js, tested on: 1.54.0-insider
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Start",
"runtimeExecutable": "${workspaceFolder}/node_modules/next/dist/bin/next",
"env": {
"NODE_OPTIONS": "--inspect"
@ivanfgm
ivanfgm / firebaseApp.js
Created August 7, 2020 14:47
Config file to integrate firebase with next.js or react projects in general
// This assumes you have a .env.local with firebase config constants
import * as firebase from 'firebase/app' // yarn add firebase
import 'firebase/auth' // if you use them
import 'firebase/firestore' // if you use them
const config = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_APIKEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTHDOMAIN,
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASEURL,
@ivanfgm
ivanfgm / mail2telegram.js
Last active January 13, 2023 10:46
Small script to send received emails to a telegram bot, easy piece thanks to: node-telegram-bot-api and mail-listener2
const makeBot = require('node-telegram-bot-api');
const mailListener = require("mail-listener2");
const config = {
// First get your telegram bot
telegramToken: 'Obtain your token talking to BotFather on telegram',
// Send a message to the bot and paste here your chat id (the response)
// TODO: login to avoid this step and allow multiple users
chatID = 'Chat ID',
// Gmail or Gsuite settings
@ivanfgm
ivanfgm / count-outside-links-analytics.js
Created March 15, 2019 16:50
Evento para contar links externos a través de eventos
@ivanfgm
ivanfgm / evaluar-profesores-saes.js
Created June 28, 2018 18:48
Una línea para evaluar profesores desde consola en SAES del IPN
var s = document.getElementsByTagName('select'), l = s.length; while (l--) s[l].value = s[l].children.length > 3 ? 5 : 2;
@ivanfgm
ivanfgm / instalar-karel-en-mac.md
Last active September 11, 2017 17:38
Instalar karel el robot en mac OS usando wine, probado en mac OS Sierra 10.12.5.

Instalar Karel el Robot en macOS

Instalar karel el robot en mac OS usando wine, probado en mac OS Sierra 10.12.5.

Consideraciones

Antes de probar algo esto, cabe mencionar que en errores de compilación del programa aparece un "Problem access violation", sólo es porque el programa no se puede compilar por un error de sintaxis, referencia, o porque hay un comentario, por alguna razón no se pueden usar comentarios. Esta forma no es perfecta, pero al menos no hay que instalar una máquina virtual.

Instrucciones

@ivanfgm
ivanfgm / responses-scrapper.js
Last active October 10, 2017 15:42
Scrap responses to a tweet directly off twitter html
function paddy(n, p, c) {
var pad_char = typeof c !== 'undefined' ? c : '0';
var pad = new Array(1 + p).join(pad_char);
return (pad + n).slice(-pad.length);
}
function formatted_date () {
var formattedDate = new Date();
@ivanfgm
ivanfgm / .htaccess-index.php
Last active June 26, 2017 22:05
htaccess file that redirects all traffic to index.php in apache.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]