This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dateutil.relativedelta import relativedelta | |
| from datetime import datetime | |
| now = datetime.now() | |
| now_plus_one_month = now + relativedelta(months=1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tweepy | |
| import codecs | |
| BRAZIL_WOEID = 23424768 | |
| twapi = tweepy.API() | |
| ret = twapi.trends_location(woeid=BRAZIL_WOEID) | |
| fhandle = codecs.open("file.txt", "w", encoding="utf-8") | |
| for trend in ret[0]['trends']: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $~ 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "" 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> 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']} |
OlderNewer