Skip to content

Instantly share code, notes, and snippets.

View perone's full-sized avatar
🙃

Christian S. Perone perone

🙃
View GitHub Profile
@perone
perone / upload.py
Created April 10, 2012 18:44
Simple flask upload
import os
from flask import Flask, request, url_for
from werkzeug import secure_filename
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
@perone
perone / gist:2938394
Created June 15, 2012 19:45
libxpto ctypes
#!/usr/bin/env python
#-*- encoding: utf-8 -*-
from ctypes import *
iLib = cdll.LoadLibrary('./libXPTO.so')
iLib.getData.argtypes = [ c_char_p, c_char_p ]
iLib.getData.restype = c_int
sInfo = create_string_buffer(1500)
@perone
perone / gist:3248889
Created August 3, 2012 15:47
Add one month
from dateutil.relativedelta import relativedelta
from datetime import datetime
now = datetime.now()
now_plus_one_month = now + relativedelta(months=1)
@perone
perone / confpar.py
Created September 13, 2012 19:26
ConfigParser attrib
import ConfigParser
class AttrDict(dict):
def __getattr__(self, key):
d = AttrDict()
for k in self.keys():
if k.startswith(key):
dcoup = k[len(key)+1:]
if not dcoup:
return self[k]
@perone
perone / trends.py
Created September 18, 2012 19:47
Trends Twitter
@perone
perone / gist:3837297
Created October 5, 2012 00:21
Scapy RTT
$~ sudo scapy
>>> from datetime import datetime
>>> pkt = IP(dst="www.google.com", ttl=1) / ICMP()
>>> ans,unans = sr(pkt*3)
Begin emission:
.**Finished to send 3 packets.
*
Received 4 packets, got 3 answers, remaining 0 packets
>>> sent = datetime.fromtimestamp(ans[0][0].sent_time)
@perone
perone / gist:3860921
Created October 9, 2012 19:33
spf13-vim local
"" https://github.com/spf13/spf13-vim
colorscheme molokai
set tags=tags;/
nmap <F8> :TagbarToggle<CR>
""map <C-o> <C-T>
map <C-o> <C-]>
set mouse=
set nonumber
@perone
perone / time_dict_value_max.py
Created December 4, 2012 00:31
Python max dict value
import timeit
t = timeit.Timer("v=sorted(d.items(), key=lambda x: x[1])[-1]",
"d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()
# 1.648s
t = timeit.Timer("v=max(d.iteritems(), key = operator.itemgetter(1))[0]",
"import operator; d = {'a': 1000, 'b': 3000, 'c':100}")
print t.timeit()
@perone
perone / pandas_table.py
Created December 5, 2012 23:27
pandas table
>>> frame = ps.read_table('alunos.txt', header=None, sep="\s*", index_col=0)
>>> frame.ix["Fulano"]
X1 8.3
X2 7.6
X3 9.5
X4 6.4
Name: Fulano
>>> frame.ix["Sicrano"]
X1 5.6
X2 8.9
@perone
perone / csvtable.py
Created December 7, 2012 18:48
reading csv table
>>> import pprint
>>> fh = open("alunos.txt")
>>> d = { v.split()[0]:v.split()[1:] for v in fh.readlines() }
>>> fh.close()
>>> pprint.pprint(d)
{'Beltrano': ['5.6', '7.8', '9.4', '5.3'],
'Fulano': ['8.3', '7.6', '9.5', '6.4'],
'Sicrano': ['5.6', '8.9', '7.4', '7.5']}