Skip to content

Instantly share code, notes, and snippets.

View jmg's full-sized avatar

Juan Manuel Garcia jmg

View GitHub Profile
@jmg
jmg / slice.py
Created April 29, 2015 15:42
slice objects in sublists sharing a common propery
def slice(objects, prop):
"""
slice objects in sublists sharing a common propery
"""
if not objects:
return []
def get_prop(obj, prop):
if not isinstance(objects[0], dict):
return obj.__dict__[prop]
@jmg
jmg / complex_square_roots.cpp
Last active April 13, 2016 04:41
Quadratic Formula with complex numbers solutions
#include <stdio.h>
#include <complex>
#include <iostream>
int main()
{
double a1,b1,c1;
printf("ingrese valor de a,b,c\n");
scanf("%lf" "%lf" "%lf", &a1, &b1, &c1);
#aca van los coeficientes de la cuadratica
a = 1
b = 0
c = -1
#aca van las cotas del intervalo
ax = -3
bx = 3
#estes es el error de la raiz en el cual cortar
#aca van los coeficientes de la cuadratica
a = 2
b = 0
c = -3
#aca van las cotas del intervalo
ax = -3
bx = 3
delta = 1
@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)
@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 / 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)
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)
import random
import time
class Card(object):
def __init__(self, number, kind):
self.number = number
self.kind = kind
@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)