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
@algal
algal / nginx-cors.conf
Created April 29, 2013 10:52
nginx configuration for CORS (Cross-Origin Resource Sharing), with an origin whitelist, and HTTP Basic Access authentication allowed
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@ecarreras
ecarreras / README.md
Last active February 16, 2017 10:34
Vivència com inquilí a un pis gestionat per Progrup

Tot acaba, o potser més aviat comença amb el retard de 6 mesos per part de Progrup en retornar una fiança de 750 euros.

Els antecedents del meu pas per un pis gestionat per Progrup, des de que vaig entrar uns 3 anys 31 de desembre del 2009 i fins que he marxat a 27 de novembre del 2012. Aproximadament uns 6 mesos i encara no se m'ha tornat la fiança.

En el moment de signar el contracte se'm va dir que era imprescindible, que el dia de la signatura del contracte, portar un xec per valor de 750 euros. Ho vaig trobar normal, ja que en tots els lloguers hi ha una fiança amb el valor del lloguer mensual.

Els primers mesos se'm va tallar fins a dos cops el suministrament d'aigua, degut a que abans d'entrar jo no es van regularitzar les factures de l'aigua i hi havia uns deutes pendents. Feina que havia de fer Progrup, però maldecaps de quedar-se sense aigua corrent dues vegades, anar en hores de feina a l'atenció al client del distribuïdor d’aigua, avançar els diners d'un deute que jo ni m'hauria d'haver assaben

@chanks
chanks / gist:7585810
Last active July 22, 2025 01:00
Turning PostgreSQL into a queue serving 10,000 jobs per second

Turning PostgreSQL into a queue serving 10,000 jobs per second

RDBMS-based job queues have been criticized recently for being unable to handle heavy loads. And they deserve it, to some extent, because the queries used to safely lock a job have been pretty hairy. SELECT FOR UPDATE followed by an UPDATE works fine at first, but then you add more workers, and each is trying to SELECT FOR UPDATE the same row (and maybe throwing NOWAIT in there, then catching the errors and retrying), and things slow down.

On top of that, they have to actually update the row to mark it as locked, so the rest of your workers are sitting there waiting while one of them propagates its lock to disk (and the disks of however many servers you're replicating to). QueueClassic got some mileage out of the novel idea of randomly picking a row near the front of the queue to lock, but I can't still seem to get more than an an extra few hundred jobs per second out of it under heavy load.

So, many developers have started going straight t

@cgoldberg
cgoldberg / img_exif_date_fixer.py
Last active October 15, 2025 12:29
Python - Fix Photo Exif Metadata
#!/usr/bin/env python
#
# gexiv2 image Exif date fixer.
# Corey Goldberg, 2014
"""Recursively scan a directory tree, fixing dates
on all jpg/png image files.
Each file's Exif metadata and atime/mtime are all
@zsup
zsup / ddd.md
Last active October 19, 2025 12:23
Documentation-Driven Development (DDD)

Documentation-Driven Development

The philosophy behind Documentation-Driven Development is a simple: from the perspective of a user, if a feature is not documented, then it doesn't exist, and if a feature is documented incorrectly, then it's broken.

  • Document the feature first. Figure out how you're going to describe the feature to users; if it's not documented, it doesn't exist. Documentation is the best way to define a feature in a user's eyes.
  • Whenever possible, documentation should be reviewed by users (community or Spark Elite) before any development begins.
  • Once documentation has been written, development should commence, and test-driven development is preferred.
  • Unit tests should be written that test the features as described by the documentation. If the functionality ever comes out of alignment with the documentation, tests should fail.
  • When a feature is being modified, it should be modified documentation-first.
  • When documentation is modified, so should be the tests.
import os
print "Descarregant PDF comers..."
os.system('curl "http://simel.simel.ree.es/sep/PubServlet2?operacion=AccInfor&fichero=117_Comercializadores.pdf" > comers.pdf')
print "Transformant a TXT..."
os.system('pdftotext comers.pdf')
print "Creant diccionari..."
c = open('comers.txt', 'r').read()
server {
listen 80;
server_name www.marcpampols.com marcpampols.com;
return 301 https://www.marcpampols.com$request_uri;
}
server {
listen 443;
ssl on;
@michaellouieloria
michaellouieloria / gist:0ff4376475b68e1e78c2
Created September 18, 2014 08:04
PDFtk commands to create fdf and fill form
create fdf
pdftk form.pdf generate_fdf output data.fdf
fill form
pdftk form.pdf fill_form data.fdf output form_with_data.pdf
@ecarreras
ecarreras / README.md
Last active August 7, 2023 07:39
PostgreSQL replication

Checklist

  • Create user replication in the master
sudo -u postgres psql -c "CREATE USER rep REPLICATION \
LOGIN ENCRYPTED PASSWORD 'thepassword';"
  • Modify postgresql.conf in the master
listen_address = # make sure we're listening as appropriate
wal_level = hot_standby

Convert HTML to Image

from html2image import HTML2Image

with HTML2Image('<html><strong>Fooo</strong></html>', width='300') as html:
    image = html.render()