Skip to content

Instantly share code, notes, and snippets.

View jabibi's full-sized avatar
🏢
Working in Madrid

Javi Melendez jabibi

🏢
Working in Madrid
View GitHub Profile
@jabibi
jabibi / indent.py
Created February 6, 2018 13:31
XML indent
# -*- coding: utf-8 -*-
def indent(elem, level=0):
tab_size = ' '
i = '\n' + level * tab_size
if len(elem):
if not elem.text or not elem.text.strip():
elem.text = i + tab_size
if not elem.tail or not elem.tail.strip():
elem.tail = i
for elem in elem:
@jabibi
jabibi / svn.keyring.sh
Last active January 4, 2018 08:40
Eclipse SVN reset user
# /home/user
cd ~
# .eclipse folder
cd .eclipse/org.eclipse.platform_3.8_155965261/configuration/org.eclipse.core.runtime
# remove file .keyring
rm .keyring
# one-line
rm ~/.eclipse/org.eclipse.platform_3.8_155965261/configuration/org.eclipse.core.runtime/.keyring
#!/usr/bin/python
import math
# [255th decimal of the constant quantity that determines the area of a circle
# by multiplying it by the radius squared]
PI_255_DECIMAL = int((math.pi * 10 ** 255) % 10) # == 8
def is_prime(num):
apt-get remove python-pip
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py
pip --version
#! /usr/bin/env python
# -*- coding: utf-8 -*-
ecs = [
"ascii",
"big5",
"big5hkscs",
"cp037",
"cp424",
"cp437",
u'Garc\xc3\xada'.encode('latin-1').decode('utf-8')
@jabibi
jabibi / timezone.py
Created August 9, 2017 13:13
It's about timezone
import datetime
import pytz
# From local timezone to UTC
pytz.timezone('Europe/Madrid').localize(datetime.datetime.now()).astimezone(pytz.utc)
# Step by step
tz = pytz.timezone('Europe/Madrid')
my_naive_datetime = datetime.datetime.now()
my_local_datetime = tz.localize(my_naive_datetime)
@jabibi
jabibi / compute_name.py
Last active July 20, 2017 08:13
_compute_name
@api.depends('proyecto_id','proyecto_id.name','tarea_id','tarea_id.name','producto_id','producto_id.name')
def _compute_name(self):
for project_material in self:
name = ""
if project_material.proyecto_id:
name += project_material.proyecto_id.name
if project_material.tarea_id:
if name != '':
name+=' - '
name += project_material.tarea_id.name
@jabibi
jabibi / csv850.py
Last active June 30, 2017 12:00
CSV cp850
# -*- coding: utf-8 -*-
import csv
def ustr(s):
return unicode(s, 'cp850', errors='replace')
with open('fichero_traspaso.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=';', quotechar='"')
for row in spamreader:
acme-tiny
anybox.buildbot.openerp
appdirs
attrs
autobahn
Babel
beautifulsoup4
behave
boltons
boto