Skip to content

Instantly share code, notes, and snippets.

@paulserraino
Created July 21, 2014 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulserraino/de595481e69b62e266f1 to your computer and use it in GitHub Desktop.
Save paulserraino/de595481e69b62e266f1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Violations</title>
<style>
body {
padding: 20px;
font-family: "helvetica neue", helvetica;
}
thead {
font-weight: bold;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<td>Violation Type</td>
<td>Violation Count</td>
</tr>
</thead>
<tbody id="results">
</tbody>
</table>
<script id="results-tmpl" type="text/x-template">
<% results.forEach(function (res) { %>
<tr>
<td><%= res.violation %></td>
<td><%= res.count %></td>
<tr>
<% }); %>
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script>
$.ajax({
type: "GET",
url: "violations.json"
}).done(function (data) {
console.log(data);
var allViolations = _.pluck(data, "violation_type");
var violations = _.uniq(allViolations);
var results = [];
_.each(violations, function (v) {
console.log(v);
results.push({
violation: v,
count: _.filter(data, function (vc) {
return vc.violation_type === v;
}).length
});
});
var tmpl = _.template($("#results-tmpl").html());
$("#results").html(tmpl({results: results}));
})
</script>
</body>
</html>
{
"dependencies": {
"request": "~2.37.0",
"csvjson": "~1.0.2"
}
}
var fs = require('fs')
var request = require('request')
var csvjson = require('csvjson')
var results = {},
csvobj;
request('http://forever.codeforamerica.org/fellowship-2015-tech-interview/Violations-2012.csv',
function (err, resp, data) {
csvobj = csvjson.toObject(data).output
csvobj = JSON.stringify(csvobj);
fs.writeFile('violations.json', csvobj, function (err) {
if (err) throw err;
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment