Skip to content

Instantly share code, notes, and snippets.

View jmg's full-sized avatar

Juan Manuel Garcia jmg

View GitHub Profile
import { useEffect, useState } from "react";
import { getAuth } from "@firebase/auth";
import Router from "next/router";
const auth = getAuth()
export const AuthGuard = ({ children, redirectUrl }: any) => {
const [isLoading, setIsLoading] = useState(true);
const [isAuthenticated, setIsAuthenticated] = useState(false);
@jmg
jmg / child.html
Last active November 4, 2019 22:59
Recibe un archivo desde una pestaña (parent.html) mediante FileReader y postMessage
<!DOCTYPE html>
<html>
<head>
<title>Child Window</title>
<script type="text/javascript">
//esta funcion escucha eventos desde parent.html para recibir los datos del archivo
window.addEventListener('message', function(e) {
@jmg
jmg / parent.html
Last active November 4, 2019 23:08
Envia un archivo a una nueva pestaña (child.html) mediante FileReader y postMessage
<!DOCTYPE html>
<html>
<head>
<title>Parent Window</title>
</head>
<body>
<div>
<input onchange="readFileContent(this)" type="file" id="input-file">
</div>
buildFormula <- function(dataset, LTerms, useTrend=FALSE, useSeason=FALSE) {
lLen <- length(LTerms)
for (i in 1:lLen)
assign(paste("fact", i, sep=""), L(dataset, LTerms[i]))
factors = array()
for (i in 1:lLen)
factors[i] <- paste("fact", i , sep="")
@jmg
jmg / build_formula.R
Last active February 22, 2018 22:15
R build form from paras
buildFormula <- function(dataset, terms_array) {
for (i in 1:length(terms_array))
assign(paste("fact", i, sep=""), L(dataset, terms_array[i]))
factors = array()
for (i in 1:length(terms_array))
factors[i] <- paste("fact", i, sep="")
form = as.formula(paste("dataset~", paste(factors, collapse="+")))
return(form)
import random
import time
class Card(object):
def __init__(self, number, kind):
self.number = number
self.kind = kind
library(quantreg)
airq <- airquality
#fit the quantile regression with Ozone formula
fit <- rq(Ozone ~ ., data=airquality)
#create a new dataframe with the values to forecast the Ozone
newdata <- data.frame(Solar.R=201:203, Wind=8:10, Temp=82:84, Month=9, Day=20:22)
#newdata is the parameter to tell the predict function to use the values for making the forecast
fore <- predict(fit, newdata=newdata)
@jmg
jmg / get_all_sum_combinations.py
Last active September 19, 2017 17:35
Gets all the combinations of the sum of a list of elements.
import itertools
def get_all_sum_combinations(elements):
"""
Gets all the combinations of the sum of a list of elements.
"""
combinations = []
for i in range(1, len(elements) + 1):
for subset in itertools.combinations(elements, r=i):
result = sum(subset)
@jmg
jmg / carrusel.html
Created November 22, 2016 04:49
Bootstrap Carrusel
<!DOCTYPE html>
<html lang="en">
<head>
<title>Carrusel Ejemplo</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Archivos de bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
@jmg
jmg / celery_check_db_connection.py
Last active May 6, 2016 03:55
Closes the db connection when it's gone because of a long period of inactivity (solves this issue https://code.djangoproject.com/ticket/21597). It forces django to use a new fresh connection.
from django.db import connection
from functools import wraps
def check_db_connection(f):
@wraps(f)
def inner(*args, **kargs):
try:
connection.connection.ping()
except:
connection.close()
return f(*args, **kargs)