Skip to content

Instantly share code, notes, and snippets.

View petulla's full-sized avatar

Sam Petulla petulla

View GitHub Profile
@dannguyen
dannguyen / nyt-list-scrape.rb
Last active August 29, 2015 14:04
A script to scrape what nytimes.com recommends to me and also, what is popular among other users
#!/usr/bin/env ruby
# nyt-list-scrape.rb
# Dan Nguyen @dancow
# Created: 2014-07-26
# Updated: 2014-07-29
#
# Scrape the titles/urls of articles recommended to the user by the NYT,
# and also, the most popular ones at the moment
#
# Requirements: Ruby 1.9.x and the Mechanize gem and a NYT digital subscriber account
-- Census tract population is column dp0010001
WITH op AS
(SELECT the_geom,
cartodb_id,
dp0010001,
Row_number() OVER (
ORDER BY Cdb_latlng(/* Starting latitude */, /* Starting longitude */) <-> the_geom) AS row_number
FROM /* Table name */ LIMIT /* Max census tracts queryable */),
sm AS
@emeeks
emeeks / d3.svg.circularbrush.js
Last active March 29, 2016 19:39
Circular Brush 3
d3.svg.circularbrush = function() {
var _extent = [0,Math.PI * 2];
var _circularbrushDispatch = d3.dispatch('brushstart', 'brushend', 'brush');
var _arc = d3.svg.arc().innerRadius(50).outerRadius(100);
var _brushData = [
{startAngle: _extent[0], endAngle: _extent[1], class: "extent"},
{startAngle: _extent[0] - .2, endAngle: _extent[0], class: "resize e"},
{startAngle: _extent[1], endAngle: _extent[1] + .2, class: "resize w"}
];
var _newBrushData = [];
@alykat
alykat / gist:5fabb42475a6111ccc38591bac09550a
Created April 1, 2016 21:18
D3: Wrap label text and make SVG taller
/*
* Wrap a block of text to a given width
* via http://bl.ocks.org/mbostock/7555321
*/
var wrapText = function(texts, width, lineHeight) {
texts.each(function() {
var text = d3.select(this);
var words = text.text().split(/\s+/).reverse();
var word = null;
@geobabbler
geobabbler / d3_squares_example.js
Last active May 25, 2016 14:55
D3 squares example for blog post
d3.json(
"data/statistics.geojson",
function (json) {
//dimensions
var w = 980;
var h = 480;
//get the center of the data
var center = d3.geo.centroid(json);
var svg = d3.select("body").append("svg")
.attr("width", w)
@emanuelfeld
emanuelfeld / gi-lf
Last active April 24, 2017 14:26
as pre-commit script, automatically add files larger than some size to your repository's .git/info/exclude file
#!/bin/bash
# set max file size to include (in MB)
max_size_mb=100
max_size_b="$(($max_size_mb * 1000000))c"
git_dir="$(git rev-parse --show-toplevel)"
git_exclude=$git_dir/.git/info/exclude
files="$(find $git_dir -path $git_dir/.git -prune -o -type f -size +$max_size_b -print | sed "s%$git_dir/%%g" | sed "s/\ /\\\ /g")"
#!/bin/bash
cd $( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
blue=$(tput setaf 4)
green=$(tput setaf 2)
normal=$(tput sgr0)
while ./update.sh
do
printf "\n${blue}>>> sleeping a little bit before running again... ${normal}\n"
@noahlt
noahlt / killport.sh
Last active September 15, 2017 16:25
killport - kill whatever process is running on a given port
# add this to your .bash_profile to use it
# source: https://gist.github.com/noahlt/2662634
function killport {
if [ ! -n "$1" ] || [ $1 == '--help' ] || [ $1 == '-h' ]
then
echo '`killport <PORT>` finds the process listening to the specified port and kills it.'
else
process_line=`sudo lsof -i :$1 | tail -1`
if [ "$process_line" == "" ]
then
@dwtkns
dwtkns / l8get
Last active October 1, 2017 20:19
A shell function to quickly grab the data for a given Landsat 8 tile ID from Google's servers
# This is a shell function to quickly grab the data for a given Landsat 8 tile ID from Google's servers
# For example:
# l8get LC81690352014169LGN00
# The echo at the end is to remind myself of the syntax for extracting bands 8, 4, 3, and 2. (Pansharp, Red, Green, Blue)
# On OSX this would go into your ~/.bash_profile file.
# Requires gsutil from https://developers.google.com/storage/docs/gsutil_install
# Most useful in conjunction with USGS' Earth Explorer: http://earthexplorer.usgs.gov/
@dwtkns
dwtkns / google-earth-perspective-to-geojson.js
Last active October 1, 2017 20:20
OSAscript to output the footprint of what's visible in the current Google Earth Pro window as a geojson file
#!/usr/bin/env osascript -l JavaScript
// usage: google-earth-perspective-to-geojson.js xSamples ySamples > currentPerspective.geojson
function run(argv) {
var xSamples = argv[0] || 50;
var ySamples = argv[1] || 50;
var ge = Application('Google Earth Pro');