Skip to content

Instantly share code, notes, and snippets.

View abusedmedia's full-sized avatar

Fabio Franchino abusedmedia

View GitHub Profile
d3.json("CIV.json", function(error, data){
var svg = d3.select('svg')
var projection = d3.geo.mercator()
.scale(30000)
.center([-2,8]);
var path = d3.geo.path()
.projection(projection);
@abusedmedia
abusedmedia / topojson_shape.js
Created October 3, 2013 13:37
Quick topojson shape visualizator code in d3.js, where `data` is the loaded json
svg.selectAll('path')
.data(topojson.object(data, data.objects.input_file).geometries)
.enter()
.append('path')
.attr('d', path)
.style('fill', '#44cccc')
@abusedmedia
abusedmedia / disable_text_selection.css
Created October 3, 2013 13:40
Don’t allow text selection on selected elements, in this case all elements.
*{
-webkit-user-select:none;
-moz-user-select:none;
user-select:none;
}
@abusedmedia
abusedmedia / get_element_scope.js
Created October 4, 2013 09:39
Get the reference Scope of a selected element
// assuming the following angular code
function Ctrl($scope){
$scope.thevar = 'SOME';
$scope.something = function(){
$scope.thevar = 'CHANGED';
}
}
// the html element:
/* <p id="el">{{thevar}}</p> */
@abusedmedia
abusedmedia / quick_touch.js
Created October 4, 2013 20:45
Add touch event attribute directive for Angular.js
angular.module('myapp', [])
.directive('quickTouch', function($parse) {
return {
restrict: 'A',
link: function(scope, elm, attrs) {
var fn = $parse(attrs['quickTouch']);
$(elm).bind('touchend mousedown', function(evt) {
scope.$apply(function() {
fn(scope, {$event: evt});
evt.stopPropagation();
@abusedmedia
abusedmedia / TableTop_example.html
Created October 7, 2013 13:41
Read data from Google SpreadSheed with few lines of code
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="description" content="TableTop simple example" />
<meta charset="utf-8">
<title>Tabletop.js test</title>
<script type="text/javascript" src="https://rawgithub.com/jsoma/tabletop/master/src/tabletop.js"></script>
</head>
<body>
@abusedmedia
abusedmedia / use_directive.js
Created October 10, 2013 20:46
Angularjs quick test on how to create directives and services as separate module, then how to use in your app.
// create directives
angular.module('whathever_namespaces', []).directive('myReusableComponent', function($parse){
return {
link: function(scope, element, attrs){
$(element).append('<h3>I\'m a reusable component</h3>');
}
};
@abusedmedia
abusedmedia / README.md
Last active August 29, 2015 14:22
Multi-series Population Growth

Population growth (annual %)

The dataset contains a list of countries and for each country there are the % value of population growth on each year, from 1960 to 2013.

The range in vertical axis is from -25% to +25%

@abusedmedia
abusedmedia / list.js
Created December 30, 2015 14:45
Get the list of elements
var arr = []
$('tbody').children().each(function(i, e){
var td = $(e).children()
if(td.length == 3){
var name = $(td[0]).find('a').text();
var link = $(td[0]).find('a').attr('href');
arr.push({name:name, link:link})
}
})
@abusedmedia
abusedmedia / README.md
Last active January 6, 2016 20:56
Food items and main nutrients

1,736 food items (each is a sample of 100g) broken down by main nutrients (Energy, Fats, Carbs, Proteins, Fiber, Sugars and Water). It's a first version that allows only comparison between nutrients, no further exploration so far.

You can click over a single chart to sort the dataset by the selected nutrient. The other charts will be updated accordingly.

This dataset has been scraped from valori-alimenti.it.

More info about the motivations behind this work in progress can be found here.