Skip to content

Instantly share code, notes, and snippets.

@veltman
veltman / gist:9500968
Last active August 29, 2015 13:57
Bad.js for @brittanystoroz, circa 2007
function fixDate(fieldname,datestr) {
//Make lowercase
newdatestr = datestr.toLowerCase();
//trim first
newdatestr = newdatestr.replace(/^\s+|\s+$/g,'');
//If it was just whitespace, don't run the function
if (!newdatestr.length) {
return;
}
@veltman
veltman / gist:9538964
Created March 13, 2014 22:58
jQuery caching
//Return a cached selection if it's been used,
//Otherwise get the jQuery selection and cache it
var $$ = function(x) {
if (!this[x]) this[x] = $(x);
return this[x];
}
$$("div.test").html("a");
$$("div.test").html("b");
ciphered = [
{
"offset": 11,
"text": "HAPCV ITGBH UDG JCXITS HIPITH RJGGTCRN"
},
{
"offset": 9,
"text": "UVRU DLJZTZREJ"
},
{
@veltman
veltman / gist:10335088
Created April 10, 2014 01:15
jQuery cacher
//Return a cached selection if it's been used,
//Otherwise get the jQuery selection and cache it
var $$ = function(x) {
if (!this[x]) this[x] = $(x);
return this[x];
};
//Use $ where the selection results might change between selections
$("div.whatever").show(); //Get a new selection
$("div.whatever").hide(); //Get a new selection
@veltman
veltman / gist:f17943b9c638ff0b4308
Created April 30, 2014 18:17
Sublime Text 2 config for Ubuntu
[Desktop Entry]
Version=1.0
Name=Sublime Text 2
# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
GenericName=Text Editor
Exec=sublime
Terminal=false
Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png
var arrows = d3.selectAll(".g-chart--reported svg").append("g").attr("class","arrows").selectAll("rect").data(d3.range(12)).enter().append("rect"),bars = d3.selectAll(".g-chart--reported svg rect.g-bar"),scale = d3.scale.linear().range([80,10]),newData = bars.data().map(function(d,i){ return d; }); arrows.attr("x",function(d,i){ return +bars.filter(function(f,j){ return j == i; }).attr("x")+3; }).attr("width",function(d,i){ return +bars.filter(function(f,j){ return j == i; }).attr("width")-6; }); setInterval(function(){newData = bars.data().map(function(d,i){ return d; }); newData = newData.map(function(d,i){ return i % 12 ? d.reported - newData[i-1].reported : null;}); scale.domain(d3.extent(newData.filter(function(d){return d !== null;}))); arrows.data(newData).style("fill",function(d){ return d < 0 ? "firebrick" : "steelblue"; }).attr("y",function(d){ return d < 0 ? scale(0) : scale(d); }).attr("height",function(d){ return d < 0 ? scale(d) - scale(0) : scale(0) - scale(d); })},200);
d3.range(2).forEach(function(chartIndex){ var chart = d3.selectAll(".g-chart--reported svg").filter(function(d,i){return i == chartIndex;}); var arrows = chart.append("g").attr("class","arrows").selectAll("rect").data(d3.range(12)).enter().append("rect"),bars = chart.selectAll("rect.g-bar"),scale = d3.scale.linear().range([80,10]),newData = bars.data().map(function(d,i){ return d; }); arrows.attr("x",function(d,i){ return +bars.filter(function(f,j){ return j == i; }).attr("x")+3; }).attr("width",function(d,i){ return +bars.filter(function(f,j){ return j == i; }).attr("width")-6; }); setInterval(function(){ newData = bars.data().map(function(d,i){ return d; }); newData = newData.map(function(d,i){ return i ? d.reported - newData[i-1].reported : i;}); scale.domain(d3.extent(newData)); arrows.data(newData).style("fill",function(d){ return d < 0 ? "firebrick" : "steelblue"; }).attr("y",function(d,i){ return d < 0 ? scale(0) : scale(d); }).attr("height",function(d){ return d < 0 ? scale(d) - scale(0) : scale(0) -
queue()
.defer(getJSON,"new-york.json")
.defer(getJSON,"chicago.json")
.defer(getJSON,"miami.json")
.awaitAll(function(error,cities) {
//Cities will be an array of cities, in order
});
function getJSON(url,cb) {
$.getJSON(url,function(data) {
cd ~/
# Add QGIS repo
sudo add-apt-repository -s "deb http://qgis.org/debian trusty main"
# Add TileMill repo
sudo add-apt-repository ppa:developmentseed/mapbox
# Update/upgrade
sudo apt-get update && sudo apt-get upgrade
with lcd("%s" % (project)):
commit = local("git log -g --pretty=%B -n 1")
print commit #This prints the right message
print commit # This doesn't