This file contains 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 sys | |
from disco import func | |
from disco.core import Job | |
def mapper((id, tweet), params): | |
import rfc822 | |
from datetime import datetime, timedelta | |
from time import mktime | |
utc_dt = datetime.fromtimestamp(mktime(rfc822.parsedate(tweet['created_at']))) |
This file contains 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
# http://i.imgur.com/Tg068.png | |
PS1='\[\033[01;34m\]`if [ \$? = 0 ]; then echo \[\e[0\;32m\]\(^_^\); else echo \[\e[0\;31m\]\(0_0\); fi` ~ ${SECONDS}s\n\[\e[1;34m\][\t \u@\h:\w]\n\[\033[1;35m\]$>\[\033[00m\] ' |
This file contains 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
bash$ python mp3box.py http://contenidos.comteco.com.bo/component/content/article/15-mp3-box/6434-top-40-usa.html | |
Downloading adele-rolling_in_the_deep.mp3 to /home/rolando/adele-rolling_in_the_deep.mp3 | |
Downloading blake_shelton-honey_bee.mp3 to /home/rolando/blake_shelton-honey_bee.mp3 | |
Downloading bruno_mars-grenade.mp3 to /home/rolando/bruno_mars-grenade.mp3 | |
Downloading bruno_mars-just_the_way_you_are.mp3 to /home/rolando/bruno_mars-just_the_way_you_are.mp3 | |
... |
This file contains 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 __future__ import division | |
def c_avrg(the_dict, exclude): | |
""" Calculate the average excluding the given element""" | |
i = 0 | |
total = 0 | |
for e in the_dict: | |
if e != exclude: | |
i += 1 | |
total += the_dict[e] |
This file contains 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
--- a/scrapy/contrib/downloadermiddleware/httpcompression.py | |
+++ b/scrapy/contrib/downloadermiddleware/httpcompression.py | |
@@ -33,7 +33,11 @@ class HttpCompressionMiddleware(object): | |
def _decode(self, body, encoding): | |
if encoding == 'gzip' or encoding == 'x-gzip': | |
- body = gunzip(body) | |
+ try: | |
+ body = gunzip(body) | |
+ except IOError: |
This file contains 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
@requestGenerator | |
def parse_profile(self, response): | |
base_url = response.url | |
ul = UserLoader(response=response) | |
ul.add_xpath('name', '//h1[1]/text()') | |
ul.add_xpath('website', '//*[@rel="me" and @class="url"]/text()') | |
ul.add_xpath('location', '//*[@class="label adr"]/text()') | |
ul.add_value('url', base_url) | |
item = ul.load_item() |
This file contains 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
"""Calculo del area cubierta por una hoja doblada.""" | |
from __future__ import division | |
import math | |
import numpy as np | |
def solve(w, h, x1, x2): | |
"""Resuelve el calculo de area cubierta de una hoja doblada. |
This file contains 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 | |
"""Square Detector | |
https://www.facebook.com/hackercup/problems.php?pid=318555664954399&round=598486203541358 | |
You want to write an image detection system that is able to recognize different geometric shapes. In the first version of the system you settled with just being able to detect filled squares on a grid. | |
You are given a grid of NxN square cells. Each cell is either white or black. Your task is to detect whether all the black cells form a square shape. |
This file contains 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
"""XPath extension functions for lxml, inspired by: | |
https://gist.github.com/shirk3y/458224083ce5464627bc | |
Usage: | |
import xpathfuncs; xpathfuncs.setup() | |
""" | |
import string |
This file contains 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 scrapy import Spider, Item, Field | |
from twisted.internet import defer, reactor | |
class MyItem(Item): | |
url = Field() | |
class MySpider(Spider): |