Skip to content

Instantly share code, notes, and snippets.

View pardo's full-sized avatar
🗒️
The documentation is my Bible

Andres Pardini pardo

🗒️
The documentation is my Bible
  • La Plata
View GitHub Profile
@pardo
pardo / rat.py
Last active February 18, 2020 01:45
#!/snap/bin/fades
import logging
from functools import wraps
from IPython import embed # fades
import sh # fades
import sys
import os
import stat
@pardo
pardo / encode_it.py
Created May 11, 2017 12:02
encode number as string
import base64
def encode(number):
out = ""
while number > 0:
first_byte = number & 0b11111111
out = chr(first_byte) + out
number = number >> 8
return out
@pardo
pardo / index.html
Last active March 10, 2017 11:44
Random Terrain Generator
<html>
<head>
<style>
body, html {
margin: 0;
padding: 0;
height: 100vh;
width: 100vw;
overflow: none;
}
from threading import Thread, Event
from Queue import Queue, Empty
class DoThreaded(object):
def __init__(self, function, concurrent=10, queue_results=None):
self.concurrent = concurrent
self.stopped = Event()
self.queue = Queue(self.concurrent)
if queue_results is None:
@pardo
pardo / dump_specs.py
Created October 14, 2016 12:52
Dump hardware specs
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
import json
import os
# CPU INFO
f = open("/proc/cpuinfo")
data = f.readlines()
f.close()
@pardo
pardo / debounced_celery_task.py
Last active September 8, 2023 08:04
Debounced celery task in python
def debounced_wrap(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
key = kwargs.pop("key") # it's required
call_count = kwargs.pop("call_count", 1)
count = cache.get(key, 1)
if count > call_count:
# someone called the function again before the this was executed
return None
# I'm the last call
@pardo
pardo / cached_method.py
Created November 5, 2015 18:06
Cached Method decorator
def cached_model_method(time=600, key_uses_args=False):
"""
Decorates django model methods
Use it as:
@cached_model_method(time=1200)
def functionToCache(arguments):
...
"""
@pardo
pardo / dump_db.sh
Last active October 5, 2015 15:40
postgresql utils
#!/bin/bash
pg_dump -h my.host.com -p 5432 -U db_name db_user | gzip > ~/backups/db_name.`date +"%Y.%m.%d_%H-%M"`.sql.gz
@pardo
pardo / log_sql.py
Created September 30, 2015 13:52
Log sql to terminal django app
import logging
l = logging.getLogger('django.db.backends')
l.setLevel(logging.DEBUG)
l.addHandler(logging.StreamHandler())
#!/bin/bash
#http://stackoverflow.com/a/18767922
function gitlist {
git branch -vv --color=always | while read; do
# The underscore is because the active branch is preceded by a '*', and
# for awk I need the columns to line up. The perl call is to strip out
# ansi colors; if you don't pass --color=always above you can skip this
local branch=$(echo "_$REPLY" | awk '{print $2}' | perl -pe 's/\e\[?.*?[\@-~]//g')
# git log fails when you pass a detached head as a branch name.
# Hide the error and get the date of the current head.