Skip to content

Instantly share code, notes, and snippets.

@gallir
gallir / gist:8e43f84b370df78ef9e5
Created January 22, 2015 23:42
test de hash y arrays
<?php
$a = array();
$b = array();
for ($i = 0; $i <50; $i+=1) {
$a[$i] = $i;
$b[] = $i;
}
@gallir
gallir / turns.c
Last active August 29, 2015 14:16
It shows OoO execution and/or write buffers and/or cache weak consistency
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#define NUM_THREADS 4
#define MAX_COUNT 10000000
struct tdata {
int tid;
@gallir
gallir / transaction_bomb.c
Last active September 28, 2015 23:24
GCC __transaction_atomic bomb
/* It will eat your memory
* But if you insist, compile it with:
gcc -pthread -fgnu-tm -mcx16 -o transaction_bomb transaction_bomb.c
*/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
import re
class BehindLB(object):
""" Middleware that get the real IP from de x-forwarded-for
Don't use it if you are not sure your load balancer return the real ip
BEHIND_LB_PATH = False
@gallir
gallir / models.py
Created October 13, 2015 20:52
Update counters per day and hostname with transactions in Google NDB
from google.appengine.ext import ndb
from datetime import datetime, timedelta, date
#
#
#
class HostConnection(ndb.Model):
date = ndb.DateProperty()
host = ndb.StringProperty()
@gallir
gallir / cactl.py
Last active October 25, 2015 10:48
A top-down recursive very simple parser
TREE = {
'proxy': {
'': proxy_list,
'list': (proxy_list, ("username", False)),
'info': (proxy_info, ("proxy_name", True)),
},
'auth': {
'': auth_info,
'info': (auth_info, ("token", False)),
func (acl *ACL) checkServer(ip string) bool {
type Params struct {
IP string `url:"ip"`
Name string `url:"name"`
}
ops := requestOps // To check laer
if _, found := acl.rejected.Get(ip); found {
log.Printf("In rejected %s", ip)
return false
@gallir
gallir / ties.py
Last active December 28, 2015 17:35
Calcula la probabilidad de empate en una votación como la de la CUP simulando resultados
#! /usr/bin/env python
import numpy.random as npr
SIZE=3030
LOOPS=1000000
TIE=SIZE/2
ties=0
@gallir
gallir / ties2.py
Created December 28, 2015 17:44
Como https://gist.github.com/gallir/18f1adea5bd5c628813d pero cada persona tiene un sesgo que afecta a su elección
#! /usr/bin/env python
""" Execute it several times to vary the biases,
which can be biased too
"""
import numpy.random as npr
SIZE=3030
LOOP=1000000
@gallir
gallir / ties3.py
Created December 28, 2015 17:49
Como https://gist.github.com/gallir/ca8d6cb958bd7767938f pero el sesgo de cada persona cambia con cada elección
#! /usr/bin/env python
import numpy.random as npr
SIZE=3030
LOOP=1000000
TIE=SIZE/2
ties=0