Skip to content

Instantly share code, notes, and snippets.

View nicolasmendoza's full-sized avatar
🎯
Focusing

Nicolás nicolasmendoza

🎯
Focusing
  • 07:08 (UTC -05:00)
View GitHub Profile
@nicolasmendoza
nicolasmendoza / gist:f0cc678137dcb2064b9b
Created February 6, 2015 05:16
request with urlib2
import urllib2
from base64 import b64encode
request = urllib2.Request('https://api.xxxx.com/user')
request.add_header('Authorization', 'Basic ' + b64encode('user' + ':' + 'pass'))
r = urllib2.urlopen(request)
print r.getcode()
print r.headers["content-type"]
print r.headers["X-RateLimit-Limit"]
@nicolasmendoza
nicolasmendoza / post.py
Last active August 29, 2015 14:15 — forked from hoest/post.py
import httplib
import xml.dom.minidom
HOST = "www.domain.nl"
API_URL = "/api/url"
def do_request(xml_location):
"""HTTP XML Post request"""
request = open(xml_location, "r").read()
import base64
"""
Some useful functions for interacting with Java web services from Python.
"""
def make_file_java_byte_array_compatible(file_obj):
"""
Reads in a file and converts it to a format accepted as Java byte array
:param file object
@nicolasmendoza
nicolasmendoza / gist:7d3a6230f8262a947215
Created May 4, 2015 17:16
Default startup script django console pych
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)
@nicolasmendoza
nicolasmendoza / gist:cc7c7f211214079f9f5b
Last active August 29, 2015 14:20
Adding shell plus + pycharm
import sys
import logging
logging.basicConfig(format="%(levelname)-8s %(asctime)s %(name)s %(message)s", datefmt='%m/%d/%y %H:%M:%S', stream=sys.stdout )
log = logging.getLogger("root")
from django.db.models import get_models
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
logging.config.dictConfig(settings.LOGGING)
@nicolasmendoza
nicolasmendoza / gist:6943df594e1d61ef8a6d
Last active August 29, 2015 14:20
Shell plus + django 1.7 + pycharm ...initialñ script
import sys
import django
django.setup()
from django.db.models import get_models
for _class in get_models():
globals()[_class.__name__] = _class
@nicolasmendoza
nicolasmendoza / 39 de 1.327 Be careful deleting files around gi
Created May 5, 2015 18:06
39 de 1.327 Be careful deleting files around gi
Working in a Python project, it's common to have a clean-up step that deletes all the .pyc files, like this:
$ find . -name '*.pyc' -delete
This works great, but there's a slight chance of a problem: Git records information about branches in files within the .git directory. These files have the same name as the branch.
Try this:
$ git checkout -b cleaup-all-.pyc

This document has now been incorporated into the uWSGI documentation:

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

Set up Django, nginx and uwsgi

Steps with explanations to set up a server using:

#!/bin/bash
# Script author: MrVaykadji http://askubuntu.com/users/176689/mrvaykadji
# Changes made by Ribtoks
# - simulink for compass2.0 in /usr/bin/
# - replaced apt commands with zypper commands
# Changes made by Andrew <andrew@webupd8.org>:
# - use the NodeJS PPA to avoid build failure with grunt-cli
# - use the Popcorn Time icon
# - added check for apt, dpkg, etc.
# - added some checks when creating symbolic links
@nicolasmendoza
nicolasmendoza / remove.sh
Last active September 7, 2015 20:28 — forked from icaoberg/remove.sh
[Git] Remove all *.pyc files from your git repository
#!/bin/bash
find . -name "*.pyc" -exec git rm {} \;
git commit -m "Removed compiled python files in distribution left after last commit"