Skip to content

Instantly share code, notes, and snippets.

View AndreaCrotti's full-sized avatar

Andrea Crotti AndreaCrotti

View GitHub Profile
### Keybase proof
I hereby claim:
* I am andreacrotti on github.
* I am andreacrotti (https://keybase.io/andreacrotti) on keybase.
* I have a public key ASAcH7o-UqMo87r8tJHWsJDJRgVb2tmovG-PLgdLZQ8NWAo
To claim this, I am signing this object:
@AndreaCrotti
AndreaCrotti / fizzbuzz.clj
Last active October 12, 2017 07:54
Recursive implementation of fizzbuzz in Clojure
(defn divides?
[n d]
(= 0 (mod n d)))
(defn remove-factor
[n d]
(if (divides? n d)
(remove-factor (/ n d) d)
n))
@AndreaCrotti
AndreaCrotti / django_logging_client.py
Last active October 19, 2016 17:36
Quick and dirty way to intercept the various get/post calls happening during Django tests
import atexit
import csv
import json
from collections import namedtuple
from django.test.client import Client
Line = namedtuple('Line', ['method', 'args', 'kwargs', 'status_code'])
class LoggingClient(Client):
df = [['method', 'args', 'kwargs', 'status_code']]
def get_last_tag(repo):
"""Return last tag object ordering by date of the commit
"""
try:
return sorted(repo.tags, key=lambda t: t.commit.authored_date, reverse=True)[0]
except IndexError:
raise NoTags("There are no tags in this repository, add a first valid one with `git tag 0.0.1`")
"""
Use functools to declare the specification of inputs and validate
them on the fly with decorator.
It also only currently works with keyword arguments only, just to keep
it simpler (and because enforcing them might be a good idea anyway).
"""
import functools
import voluptuous as V
"""
Fun with toolz, wirting a decorator that merge dictionaries yielded from a genrator into a single result.
"""
import toolz
def merge_dicts(func):
"""Consume a generator that would yield dictionaries and merge them
all together
@AndreaCrotti
AndreaCrotti / create_table_from_sqlalchemy.py
Created August 10, 2015 12:57
print out schema from sqlalchemy
import argparse
import inspect
from importlib import import_module
from sqlalchemy import create_engine
from sqlalchemy.schema import CreateTable
from skim.slxmodels.meta import BaseModel
import argparse
import multiprocessing
import threading
from pylibmc.test import make_test_client
import random
NUM_THREADS = 4
NUM_PROCS = 4
NUM_SETS = 1000
@AndreaCrotti
AndreaCrotti / gist:4132917
Created November 22, 2012 21:05
santa sol
# draw things out of a hat
from pprint import pprint
import re
import random
NAME_REGEXP = re.compile("(?P<name>\w+) (?P<last>\w+) <(?P<mail>.*?)>")
NAMES = [
@AndreaCrotti
AndreaCrotti / Application.scala
Created October 18, 2012 22:33
scala-play solution to scala-coding dojo 18-10-2012
package controllers
import play.api._
import play.api.mvc._
object Application extends Controller {
def is_cube(a: Int): Boolean = {
(1 to (a / 2)).exists(x => x * x * x == a)
}