Skip to content

Instantly share code, notes, and snippets.

@dheerosaur
dheerosaur / process_excel.py
Created June 14, 2017 11:40
An example of processing an Excel sheet
def process_cell(cell):
if cell.is_date and cell.value:
return cell.value.strftime('%m/%d/%Y')
elif '"$"#' in cell.number_format:
if isinstance(cell.value, float) or isinstance(cell.value, int):
return '${:,.2f}'.format(cell.value)
return cell.value
def process_claims(sheet):
@dheerosaur
dheerosaur / char-counter.js
Created May 25, 2017 05:10
Text input character counter
(function ($) {
function updateCharCount($obj, text, max_char) {
var contentLength = text.length;
$obj.find('.char-count').text(contentLength);
if (contentLength > max_char) {
$obj.removeClass('text-navy').addClass('text-danger');
} else {
$obj.removeClass('text-danger').addClass('text-navy');
}
var dataCache = {};
function getData (query) {
var key = query.startDate;
if ( !(key in dataCache) ) {
dataCache[key] = $.getJSON('/trip?', query);
}
}
function getNextChunk (params) {
var transform, d3path;
function initSVG() {
transform = d3.geo.transform({ point: projectPoint });
d3path = d3.geo.path().projection(transform);
}
// We do the following for each feature
feature.geometry.coordinates = polyline.decode(
feature.geometry.coordinates);
map = L.map('map', {zoomControl: false});
map.fitBounds([[40.869693, -74.170267], [40.546460, -73.772013]]);
var MAP_ROOT = 'http://{s}.tiles.mapbox.com/v4/MAP_ID'
, TOKEN = 'Access token from Mapbox';
L.tileLayer(MAP_ROOT + '/{z}/{x}/{y}.png?access_token=' + TOKEN, {
attribution: 'Attribution text and links',
maxZoom: 18,
# bin/get_directions.py gets us with_directions.csv
# This can be easily loaded into SQLite:
> create table trips (vendor, 'pickupTime' DATETIME, duration, terminal, direction);
> .mode csv
> .import with_directions.csv trips
# To get daily counts from the SQL
> select DATE(pickupTime), count(1) from trips group by DATE(pickupTime)
@dheerosaur
dheerosaur / query-params
Created May 30, 2013 19:56
Get some parameters from the query string as an object.
/* Get querystring parameter's value */
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return null;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
@dheerosaur
dheerosaur / default.js
Created December 12, 2011 07:54
Hiding stuff, go directly to "My active tickets" in unfuddle
// Reusable extension for jQuery so that we can hide jQuery objects
// and hide them. We will show an arrow at the top-right corner which
// will toggle the display of these.
// Examples:
//
// For github.com.js:
// $("#header").toggleStuff();
//
// Some random site:
// $("#report_attachment").parent().next().toggleStuff()