Skip to content

Instantly share code, notes, and snippets.

View martindrapeau's full-sized avatar

Martin Drapeau martindrapeau

View GitHub Profile
// Subclass the Backbone model to keep the model and its state (errors)
// sent back by the server. Creates a new errorModel property holding
// a Backbone model with errors, mapped to the model attributes.
Backbone.ModelWithState = Backbone.Model.extend({
errorModel: undefined,
constructor: function(attributes, options) {
Backbone.Model.apply(this, arguments);
options || (options = {});
this.errorModel = options.errorModel || new Backbone.Model();
},
@martindrapeau
martindrapeau / gist:561616cf5b5ed9fc58a6
Created August 29, 2014 03:01
Rename files replacing non ASCII by _
find /path/to/files -type f -print0 | \
perl -n0e '$new = $_; if($new =~ s/[^[:ascii:]]/_/g) {
print("Renaming $_ to $new\n"); rename($_, $new);
}'
@martindrapeau
martindrapeau / planbox_time_report.js
Created October 13, 2011 15:04
Planbox Current Iteration Time Report
var stories;
var resources;
function doWork() {
var sums = {};
for (var i=0; i < resources.length; i++) {
var resource = resources[i];
sums[resource.id] = {
name: resource.name,
stories: {},
estimate: 0,
@martindrapeau
martindrapeau / planbox_burndown_data.js
Created October 13, 2011 15:10
Planbox Burndown Data in Current Iteration
var iteration;
function doWork() {
var burndown = iteration.burndown;
var product_data = burndown.data[0];
var dates = burndown.dates;
console.log('Points remaining in iteration');
for (var i=0; i&lt;dates.length; i++) {
var remain = product_data.points[i];
if (remain != null) {
@martindrapeau
martindrapeau / gist:1438680
Created December 6, 2011 15:57
Planbox Velocity for the Current Iteration
$.post('https://www.planbox.com/api/get_iterations',
{product_id:1234, timeframe:"current"},
function(object) {
var iterations = object.content;
var iteration = iterations[0];
console.log('Your velocity for iteration '+iteration.name+' averaged on the past '+iteration.velocity.iteration_ids.length+' iterations:');
var record = iteration.velocity.data[0];
console.log(' Estimate-hours Velocity = '+Math.round(record.estimate_done));
console.log(' Points Velocity = '+Math.round(record.points_done));
console.log(' Business Value Velocity = '+Math.round(record.value_done));
@martindrapeau
martindrapeau / gist:1467822
Created December 12, 2011 15:23
Planbox My Itemsin All Initiatives
$.post('https://www.planbox.com/api/get_products', function(data) {
var products = data.content;
var product_ids = [];
var product_id2name = {};
for (var i=0; i<products.length; i++) {
var product = products[i];
product_id2name[product.id] = product.name;
product_ids.push(product.id);
}
$.post('https://www.planbox.com/api/get_stories',
@martindrapeau
martindrapeau / telerik-patch.js
Last active January 1, 2016 18:19
Patches Telerik Tooltip control in IE10 which fails with Javascript error
/*
* Patches Telerik Tooltip control in IE10 which fails with this Javascript error:
*
* SCRIPT5007: Unable to get property 'documentElement' of undefined or null reference
* Telerik.Web.UI.WebResource.axd, line 151 character 2
*
* Solution is to redefine the bugged function and replace a.document.documentElement
* with (a.document || a.ownerDocument).documentElement, thus avoiding a paid upgrade.
*
* To use, include this script after Telerik's.
$(document).ready(function() {
getActivities('992572', gotCategory);
});
function gotCategory(data) {
console.log(data);
var tbody = document.getElementById('tb_activity');
function loadImage(url, callback) {
var img = document.createElement("img");
img.src = url;
if (callback) {
img.onreadystatechange = callback;
img.onload = callback;
}
}
var screenWidth = Math.max(window.screen.width * window.devicePixelRatio, window.innerWidth);
var factor = screenHeight >= 960 ? 2 : 1;
if (screenHeight >= 960*2) factor = 3;
if (screenHeight >= 960*2.5) factor = 4;
// Image urls are then modified to load the proper size:
imgUrl.replace(".png", factor + ".png");