Skip to content

Instantly share code, notes, and snippets.

View ebergam's full-sized avatar

Enrico Bergamini ebergam

  • Barcelona
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ebergam
ebergam / Mappa_D3_Leaflet.html
Last active September 30, 2015 19:18
A simle map of the towns in the Province of Ferrara, Italy. Following this work: http://bl.ocks.org/d3noob/9267535
<!DOCTYPE html>
<meta charset="utf-8">
<html>
<head>
<title>Come fare una mappa con D3.js e Leaflet.js</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
@ebergam
ebergam / Senato.html
Created February 7, 2016 10:12
Cambio casacca - Senato
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://d3js.org/d3.v2.js"></script>
<script type="text/javascript" src="./sankey.js"></script>
<title>Cambio casacca al Senato</title>
<style>
@ebergam
ebergam / Geocoded_UK_Jails.csv
Last active March 12, 2016 18:53
A geocoded and updated list of UK jails, linking to their Ministry of Justice page
Name URL Latitude Longitude
Northumberland https://www.justice.gov.uk/contacts/prison-finder/acklington2 55.2082542 -2.0784138
Altcourse https://www.justice.gov.uk/contacts/prison-finder/altcourse 53.460316 -2.935761
Ashfield https://www.justice.gov.uk/contacts/prison-finder/ashfield 51.48264 -2.438431
Askham Grange https://www.justice.gov.uk/contacts/prison-finder/askham-grange 53.925882 -1.184179
Aylesbury https://www.justice.gov.uk/contacts/prison-finder/aylesbury 51.822498 -0.802383
Bedford https://www.justice.gov.uk/contacts/prison-finder/bedford 52.13894 -0.469711
Belmarsh https://www.justice.gov.uk/contacts/prison-finder/belmarsh 51.491742 0.0873507
Birmingham https://www.justice.gov.uk/contacts/prison-finder/birmingham 52.494514 -1.938855
Blantyre House https://www.justice.gov.uk/contacts/prison-finder/blantyre-house 51.13419 0.503972
@ebergam
ebergam / scrape_n_feed.py
Created December 19, 2017 12:58
Scrape and feed
import urllib2, datetime
from lxml import etree
from yattag import Doc
url = "http://enricobergamini.it/scrape_feed_tutorial.html"
#this functions transforms a date written as '03/24/2017' into an RSS valid 'Fri, 24 Mar 2017 00:00:00 +0200'
def clean_date(x):
try:
d = datetime.datetime.strptime(x.text, '%m/%d/%Y')
@ebergam
ebergam / pandapivot.py
Last active February 6, 2018 09:21
Non-numeric pivot tables in Pandas
import pandas as pd
import csv
df = pd.read_csv('data_raw.csv')
df
pivot_table = df.pivot_table(index=['id'],
columns=['key'],
values=['value'],
aggfunc=lambda x: ' '.join(str(v) for v in x))
pivot_table.to_csv('data_pivot.csv')
@ebergam
ebergam / aa.md
Last active April 24, 2018 13:25
prova

Hello there! This is a sample post for gist.io, a super-lightweight writing soapbox for hackers.

Now look up. Further. Above the post title. See that grey text with the gist ID?

Now back to me. That grey text is a link! Open that sucker in a new tab to see the source for this post. Also, I'm on a horse.

This is a major heading

<!DOCTYPE html><html><head>
<meta charset="UTF-8">
<title>prova</title>
</head>
<body><div><style>
</style>
<iframe class='viz-container' src="https://public.tableau.com/profile/actionaid.bologna#!/vizhome/dashboard2017_0/Dashboard3?:embed=y"></iframe>
</div>
# -*- coding: utf-8 -*-
import sys, re, time, logging, requests
import random
import unicodecsv as csv
from threading import Thread, Lock, currentThread
from queue import Queue, Empty
from lxml import html
lock = Lock()
@ebergam
ebergam / movingscatter.py
Last active May 15, 2019 11:09
Moving Scatter
graph = px.scatter(df, x="employment", y="equity", #color="country",
hover_name="country", text="countrycode",
range_x=[48,80], range_y=[76,93], template="plotly_dark", size="pop",
animation_group="country", animation_frame="year",
labels=dict(employment="Emp", equity="Eq",year="Year"))
for i in graph['data']:
i['name'] = i['name'].replace('Country=', '')