Skip to content

Instantly share code, notes, and snippets.

@elpargo
elpargo / gist:5661274
Created May 28, 2013 08:19
API de provincias de RD.
import falcon #webframework
import json #json duh!
import requests #sane http get/post/etc.
from bs4 import BeautifulSoup #sane htmlparser
def get_soup():
#Link u guys provided.... get me the .json !!!!
html_doc = requests.get("http://www.jmarcano.com/mipais/geografia/province/municipios/").text
if not html_doc:
#lame sanity check. TODO: make proper
@elpargo
elpargo / provinciasapp.py
Created May 28, 2013 12:26
API de provincias v2 + tester + runner
import falcon #webframework
import json #json duh!
import requests #sane http get/post/etc.
from bs4 import BeautifulSoup #sane htmlparser
def get_soup():
#Link u guys provided.... get me the .json !!!!
html_doc = requests.get("http://www.jmarcano.com/mipais/geografia/province/municipios/").text
if not html_doc:
#lame sanity check. TODO: make proper
import operator
# Estas cedulas fueron emitidas por la JCE, pero no cumplen con el
# digito verificador, por lo cual deben ser verificadas por separado.
excepcionesCedulas = ['00000000018', '11111111123', '00100759932', '00105606543', '00114272360', '00200123640',
'00200409772', '00800106971', '01200004166', '01400074875', '01400000282', '03103749672',
'03200066940', '03800032522', '03900192284', '04900026260', '05900072869', '07700009346',
'00114532330', '03121982479', '40200700675', '40200639953', '00121581750', '00119161853',
'22321581834', '00121581800', '09421581768', '22721581818', '90001200901', '00301200901',
'40200452735', '40200401324', '10621581792'];
@elpargo
elpargo / gist:5753520
Created June 10, 2013 23:57
Como sobrevivir en devdom
- si el post original dice "mejor" skip it.
- si dice offtopic you should read it.
- si dije java y .net en la misma oracion skip it.
- Si melvyn arranco el post skip it.
- If it has more than 50 replies skip it.
- if marmolejos answered first skip it.
- if Orly quotes the rules skip it.
- if it contains php next, probably not worth it.
- si dice morrison, dodo o software libre skip it.
@elpargo
elpargo / provinciasdjangoapp.py
Last active December 18, 2015 10:58
Initial version of provinciasapp in django (won't run just for showing purposes) repo coming.... This behaves like the data repository. That is asking for the data structure will bring all the json below it. ie: ```bash http://127.0.0.1:8000/ -> all data http://127.0.0.1:8000/1 -> all data for country 1 http://127.0.0.1:8000/1/Provincia/ -> all …
from django.http import HttpResponse
from django.utils import simplejson as json
from django.views.generic.list import BaseListView
def json_render_to_response(context):
"Returns a JSON response containing 'context' as payload"
payload = json.dumps(context)
json_response = HttpResponse(payload,content_type="application/json")
return json_response
@elpargo
elpargo / gist:5874321
Created June 27, 2013 06:11
Indice de la charla de PythonDominicana sobre Debugging
debug
print/pprint
logging
import pdb;pdb.set_trace()
import ipdb;ipdb.set_trace()
import code;code.interact(local=locals())
https://nose.readthedocs.org/en/latest/testing_tools.html#nose.tools.set_trace
nose --pdb or --pdb-failures
other functions in pdb/ipdb
>>> range(0) == True
False
>>> range(1) == True
False
>>> if range(1):
... print True
...
True
>>> if not range(0):
... print False
@elpargo
elpargo / gist:6096893
Created July 28, 2013 00:40
Make the ruby idiom foo.days.ago work in python.
from forbiddenfruit import curse
from datetime import timedelta,datetime
curse(int,'days',property(lambda s:timedelta(s)))
(12).days
curse(timedelta,'ago',property(lambda s:datetime.now()-s))
print (12).days.ago
class Player
def initialize()
@health = 21
@forward = :forward
@backward = :backward
@direction = @forward
end
def play_turn(warrior)
spaces = warrior.look(:forward)
class Signal(object):
def __init__(self,providing_args):
pass
signals = {'hook': [Signal(providing_args=a) for a in ['change','...']]}
#output is
# {'hook': [<__main__.Signal object at 0x10334dcd0>, <__main__.Signal object at 0x10334dd10>]}