Skip to content

Instantly share code, notes, and snippets.

View jorge-lavin's full-sized avatar
:bowtie:
Focus

Jorge Lavin jorge-lavin

:bowtie:
Focus
View GitHub Profile
@jorge-lavin
jorge-lavin / reverse_list_fft.py
Created January 13, 2015 12:06
Reverse List for FFT
# As stated in the SciPy documentation for fft http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.fftpack.fft.html
# Note that y(-j) = y(n-j).conjugate().
# This is a possible implementation of that equality.
import numpy as np
from scipy.fftpack import fft
x = np.linspace(-np.pi, np.pi, 201)
y = fft(x)
@jorge-lavin
jorge-lavin / README
Created December 19, 2014 11:02
Mock and monkey patching example
Folder structure should be like
test_my_package.py
my_package/
__init__.py
my_module.py
Requieres mock to be available
Usage: python test_my_package
@jorge-lavin
jorge-lavin / gist:238ccb229ac594a50b0a
Created November 25, 2014 13:03
SMTPHandler with support to attachments
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.Utils import formatdate
from logging.handlers import SMTPHandler
import logging
import os.path
import smtplib
@jorge-lavin
jorge-lavin / ascii_grep
Created October 22, 2014 13:40
non ascii in files with grep
grep --color='auto' -P -n "[\x80-\xFF]" /file.txt
import sys
def force_trust():
'''Checks if we need to trust all certificates
#FIXME: Not only check Jython, check if Jython was compiled with SSL support'''
if 'java' in sys.platform:
return True
else:
return False
@jorge-lavin
jorge-lavin / prepare_logger.py
Created October 1, 2014 14:31
prepare_logger
def prepare_logger(options, logging_config_file='logging.ini'):
"""Logging configuration, via logging configuration file and initialization.
@param options: a dictionary with the values of the variables reference in the logging configuration file.
@param logging_config_file: (Optional) If specified, its a full qualified path name to a logging configuration file
@raise IOError: If the logging configuration file is not accesible"""
if logging_config_file:
log_ini_path = logging_config_file
@jorge-lavin
jorge-lavin / current_shell
Created September 24, 2014 10:19
To know your current shell
# In case you're using more than one shell at a time, say, bash, then ksh then bash .. and so forth
# you may wanna know which is the current shell active
# $$ contains the PID of the parent process (i.e., the spawned shell)
my_shell=`ps -p $$ | tail -1 | awk '{print $NF}'`
echo ${my_shell}
class JLI(object):
"""JLI"""
def __init__(self):
pass
def check_verbose(self):
try:
self.verbose
except AttributeError:
return False
import sys
import random
import logging
logging.basicConfig(format='[%(levelname)5s] %(message)s',level=logging.DEBUG)
def run(program=''):
"""Function to be wrapped"""
if not program:
raise OSError('Not program specified to run.')
import BaseHTTPServer
def keep_running():
user_keystroke = raw_input()
if user_keystroke == 'q':
return False
else:
return True
def run_while_true(server_class=BaseHTTPServer.HTTPServer,