Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View pfreixes's full-sized avatar

Pau Freixes pfreixes

  • Github
  • Barcelona
View GitHub Profile
@pfreixes
pfreixes / gist:8e45a12b671aecd54b8e
Last active August 29, 2015 14:02
Graphite, Carbon and Whisper files ... under the hood
GET /render?target=x
^
| |
| |
| |
+--|---------------------------+
| | | |
| | +--------------+ |
| | | consolidation| |
| | +--------------+ |
@pfreixes
pfreixes / gist:1b4c9f0cf1c2bd19edf9
Created June 1, 2014 09:19
Whisper data format ....
Whisper data base format
------------------------
Byte Map of whisper file format
+------------------+
| Aggregation func | 4 bytes - Type of allocate strategies for file
+------------------+ * Use of fallocate if it is available, book the disk space
| Max time | * Use of sparse, fragmented, if it is configured.
| retention | 4 bytes * Booking whole space writing zeros over there
Whisper example of update value
-------------------------------
Have a look to Whisper data format map to learn how it is https://gist.github.com/pfreixes/1b4c9f0cf1c2bd19edf9
Network packets : ts value
+------------------+
| 1401614544 10.0 | packet 1
@pfreixes
pfreixes / gist:4aea1c5642c85b80efe8
Last active August 29, 2015 14:02
A not negligible difference between Python 2 and Python 3
"""Programs not ported to Python 3 that they are using specific
operations with strings could raise undesirable bugs"""
>>> title = "Open binary file with python 3"
>>> fd = open("/tmp/wut.png", "rb")
>>> b = fd.read()
>>> type(b)
<class 'bytes'>
>>> b[0] == "\x89"
False
@pfreixes
pfreixes / gist:592d8d6fcf5291f510ed
Created July 7, 2014 09:20
rabbitmq event exchange, list of events
List of available events and their topics used by
rabbitmq-event-exchange.
queue.*
consumer.*
user.*
permission.*
channel.*
policy.*
vhost.*
@pfreixes
pfreixes / gist:2b214ef3b8fc96f62825
Created July 28, 2014 19:10
Get benefit of current BTree implemenation of indexes in Mongodb
> db.test.find().count()
13
> db.test.find()
{ "_id" : "01-02" }
{ "_id" : "01-01" }
{ "_id" : "01-03" }
{ "_id" : "02-01" }
{ "_id" : "02-02" }
{ "_id" : "02-03" }
{ "_id" : "03-01" }
@pfreixes
pfreixes / gist:25b7f7713ac29f8aefba
Last active August 29, 2015 14:08
Is works because of immutability of integer python implementation
Boolean are integers, integers are immutable and immutable objects are shared along the life cycle of your programm. Then it comes true
>>> False is False
True
>>> 123 is 123
True
>>> [1] is [1]
False
@pfreixes
pfreixes / gist:e7f6f89f7ef60234b5dc
Created February 20, 2015 17:34
Use memoization to speedup the python version
#!/usr/bin/env python
UPPER_ITERATIONS = 10000000
def fac(n):
if n == 0:
return 1
return n * fac(n - 1)
@pfreixes
pfreixes / gist:ac9974bde0dcfe500f5a
Created April 4, 2015 17:36
Because the way matters #python and prime numbers
N = 100000
# First approximation, brute force
def is_prime(number):
if number == 2:
return True
for x in range(2, number/2+1):
if number % x == 0:
return False
return True
@pfreixes
pfreixes / consumers_trheaded_vs_asyncronous.md
Last active August 29, 2015 14:25
1K pika consumers, asyncronous vs thread

All consumers consuming over 1K queues, growing from 1 to 1K messages.

consumer_threaded_pika.py

import pika
import threading
import sys
import time