Skip to content

Instantly share code, notes, and snippets.

View ricrogz's full-sized avatar

Ricardo Rodriguez ricrogz

View GitHub Profile
https://open.spotify.com/user/jhiggy58/playlist/1xvz50JtGUQdYuJLBMKA13
@ricrogz
ricrogz / py_real_obj_size.py
Last active October 14, 2017 23:14 — forked from bosswissam/pysize.py
Get Real size of objects in python
import sys
def get_size(obj, seen=None):
"""Recursively finds size of objects"""
size = sys.getsizeof(obj)
if seen is None:
seen = set()
obj_id = id(obj)
if obj_id in seen:
return 0
@ricrogz
ricrogz / nginx+gunicorn+virtualenv+django tutorial.md
Last active April 5, 2024 21:21
nginx+gunicorn+virtualenv+django tutorial

Taken from: http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/

Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL

[Django][1] is an efficient, versatile and dynamically evolving web application development framework. When Django initially gained popularity, the recommended setup for running Django applications was based around Apache with mod_wsgi. The art of running Django advanced and these days the recommended configuration is more efficient and resilient, but also more complex and includes such tools as: Nginx, Gunicorn, virtualenv, supervisord and PostgreSQL.

In this text I will explain how to combine all of these components into a Django server running on Linux.

@ricrogz
ricrogz / timeout.sh
Last active April 15, 2017 09:31
Bash command timeout with warning on forced termination
# seen here: https://unix.stackexchange.com/questions/58304/is-there-a-way-to-call-a-command-with-a-set-time-limit-and-kill-it-when-that-tim
timeout() {
time=$1
# start the command in a subshell to avoid problem with pipes
# (spawn accepts one command)
command="/bin/sh -c \"$2\""
@ricrogz
ricrogz / smaller_primes.py
Last active March 25, 2017 12:02
Primes smaller than n
# Adapted from here: https://groups.google.com/forum/#!msg/comp.lang.python/dUOqrbnpKeI/LYzGiO0M8fEJ
def smaller_primes(n):
"""Given an integer n, compute a list of the primes <= n"""
if n < 2:
return []
sieve = list(range(3, n + 1, 2))
top = len(sieve)
@ricrogz
ricrogz / factorize.py
Last active March 25, 2017 11:51
Efficient factorization in python
# Seen here: http://stackoverflow.com/questions/16996217/prime-factorization-list
def factorize(n):
primfac = []
d = 2
while d*d <= n:
while (n % d) == 0:
primfac.append(d) # supposing you want multiple factors repeated
n //= d
convert -density 300 proyectos.pdf -compress LZW -resample 150 -colors 31 test.pdf
### Keybase proof
I hereby claim:
* I am ricrogz on github.
* I am invik (https://keybase.io/invik) on keybase.
* I have a public key whose fingerprint is 5D76 3A33 A52C 586F 9537 BA40 D076 E68B D60E 8400
To claim this, I am signing this object:
@ricrogz
ricrogz / gist:bef9042e1e4928f8b9cda720cac72b53
Created December 23, 2016 15:45
Google Custom Search JSON API example
# coding: utf-8
api = "api_key"
search_id = "search_id_code"
query = "query words"
url="https://www.googleapis.com/customsearch/v1?key={}&cx={}&q={{}}&fields=items(link)&dateRestrict=y2&start=11".format(api, search_id);
a = requests.get(url.format(query)); print(a.status_code); a.json()
@ricrogz
ricrogz / my-cartpole-rev1.py
Created August 10, 2016 12:53
OpenAI -- CartPole-v0
#!/usr/bin/env python2
"""
I am new both to OpenAI and AI itself.
I have to (shamelessly) admit that I have just taken the coded uploaded by 'shanest'
from his write up (https://gym.openai.com/evaluations/eval_RE77KlTNTvCGzTgtm0Qqg),
studied it, and lightly tweaked it with my own ideas.