Skip to content

Instantly share code, notes, and snippets.

View edgabaldi's full-sized avatar

Edgar Gabaldi edgabaldi

View GitHub Profile
mplayer -vo xv tv:// -tv driver=v4l2:width=640:height=480:fps=30:device=/dev/video0
@edgabaldi
edgabaldi / mock_file_field.py
Created July 13, 2016 18:07
Mocking Django Filefiled
from django.core.files import File
s = SimpleModel()
s.audio_file = File(open("media/testfiles/testaudio.wav"))
s.save()
@edgabaldi
edgabaldi / json_serializer.py
Created December 11, 2015 01:34
JSON Serialize Example
>>> import json
>>> import datetime
>>> from django.core.serializers.json import DjangoJSONEncoder
>>> di = {'now': datetime.datetime.now()}
>>> json.dumps(di, cls=DjangoJSONEncoder)
'{"now": "2015-12-10T23:32:42.344"}'
@edgabaldi
edgabaldi / example.py
Created October 24, 2015 20:57
Download photo with requests and saving in Django ImageField
import requests
from StringIO import StringIO
from product.models import Product, Photo
from django.core.files.base import ContentFile
response = requests.get('http://photo-url/image.jpg')
file = StringIO(response.content)
file_content = ContentFile(file.read())
@edgabaldi
edgabaldi / randomize.py
Created October 22, 2015 02:39
Generate Randon valid CPF (unfinished)
class Randomize(object):
def _get_multiplier(self):
if not hasattr(self, 'multiplier') or \
self.multiplier == None:
self.multiplier = 2
else:
if self.multiplier == 9:
@edgabaldi
edgabaldi / example.py
Last active September 3, 2015 20:05
Annotate example
class Company(models.Model):
name = models.CharField(max_length=100)
class Product(models.Model):
name = models.CharField(max_length=100)
class Quotation(models.Model):
product = models.ForeignKey('app.Product', related_name=quotations)
company = models.ForeignKey('app.Company')
price = models.DecimalField(...)
@edgabaldi
edgabaldi / book_reco.ipynb
Last active August 31, 2015 22:57 — forked from mickaellegal/book_reco.ipynb
iPython Notebook: Blog book recommendation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@edgabaldi
edgabaldi / index.html
Created August 18, 2015 19:02
Manually render an angular template from ng-template inside directive
<!DOCTYPE html>
<html ng-app="fooBar">
<head>
<script data-require="angular.js@*" data-semver="1.4.3" src="https://code.angularjs.org/1.4.3/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script type="text/ng-template" id="tpl.html">
<h1>{{message}}</h1>
</script>
<script src="script.js"></script>
@edgabaldi
edgabaldi / TODO.txt
Last active August 29, 2015 14:26
easy way to write xls files with a dict/tuple
* easy way to set style of a sheet
* totalization ?
* Use more that one "table" by sheet.
- Maybe use cursors. (self.cursor_row, self.cursor_line)
@edgabaldi
edgabaldi / __init__.py
Last active August 29, 2015 14:25
post migrate signal that create new permissions
#coding:utf-8
from south.signals import post_migrate
def update_permission_after_migration(app, **kwargs):
"""
your_project.__init__.py is a nice place to stay
Update app permission just after every migration.
This is based on app djando_extensions update_permissions management command.
"""