Skip to content

Instantly share code, notes, and snippets.

View ecarreras's full-sized avatar
💡
IT for utilities

Eduard Carreras ecarreras

💡
IT for utilities
View GitHub Profile
for addr_id in O.ResPartnerAddress.search([]):
addr = O.ResPartnerAddress.get(addr_id)
vals = {}
for field in ('phone', 'mobile'):
if getattr(addr, field):
addr_val = getattr(addr, field)
updated = ''.join([x for x in addr_val if x.isdigit()])
if len(updated) == 9:
vals[field] = updated
@ecarreras
ecarreras / dump.sh
Last active December 16, 2015 22:39
pg_dump --no-owner -T ir_attachment* $DBNAME \
| sed -e 's/\t\\\\x[a-z0-9]*//g' -e 's/ logo,//g' > $DBNAME.sql
#!/usr/bin/env sh
if [ -z $VIRTUAL_ENV ]; then
echo "**ERR: No virtualenv active"
exit 1
fi
if [ ! -e $VIRTUAL_ENV/bin/postgres ]; then
echo "**ERR: No postgres binary for this virtualenv: ${VIRTUAL_ENV}"
exit 1
fi
echo "Starting PostgreSQL for virtualenv: ${VIRTUAL_ENV}"
from flask import Flask, request
app = Flask(__name__)
@app.route('/', defaults={'path': ''}, methods=['GET', 'POST', 'PUT', 'PATCH'])
@app.route('/<path:path>', methods=['GET', 'POST', 'PUT', 'PATCH'])
def main(path):
print 'Path requested: %s' % path
for key, value in request.headers:
@ecarreras
ecarreras / create_index
Created March 22, 2013 12:41
Índex de MongoDB pel STG
db.tg_billing.ensureIndex({'_id': 1}, {background: true})
db.tg_billing.ensureIndex({'id': 1}, {background: true})
db.tg_billing.ensureIndex({'date_end': -1}, {background: true})
db.tg_billing.ensureIndex({'name': 1}, {background: true})
db.tg_billing.ensureIndex({'type': 1, 'name': 1, 'value': 1, 'period': 1}, {background: true})
db.tg_billing.ensureIndex({'date_end': -1, 'valid': 1}, {background: true})
REC=3
FOUND=0
find_and_build_makefile()
{
echo "Searching in `pwd`..."
res=$(find . -name 'Makefile')
if [ -z $res ]; then
cd ..
else
echo "Sphinx Makefile found!"

Paralize your scripts with Redis

  1. Setup your redis server
  2. Install python-rq
  3. Clone this gist
  4. Start n workers
  5. Run tas_rq.py
  6. Wait workers do the job :)
<xpath expr="//form/group[5]/group[1]" position="attributes">
<attribute name="attrs">[('informe','not in','(export_factures_desglossat', 'export_trams_potencia_i_municipi'))]}</attribute>
</xpath>
<xpath expr="//form/group[5]/group[2]" position="attributes">
<attribute name="attrs">[('informe','in','(export_factures_desglossat', 'export_trams_potencia_i_municipi'))]}</attribute>
</xpath>
@ecarreras
ecarreras / pr.md
Last active December 14, 2015 21:28 — forked from kennethreitz/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add a new remote. Obviously, change the github url to match your project's URL. It ends up looking like this: