Skip to content

Instantly share code, notes, and snippets.

@optilude
optilude / registry.js
Last active December 19, 2015 10:49
Generic, asynchronous, dependency-aware, promise-based operations registry
/*jshint globalstrict:true, devel:true */
/*global require, module, exports, process, __dirname */
"use strict";
var Toposort = require('toposort-class'),
promise = require('node-promise'),
_ = require('underscore');
module.exports = (function() {
SELECT `planDays`.`projectId` AS `projectId`,
`planDays`.`allocationId` AS `allocationId`,
ROUND(SUM(`planDays`.`hours` *
(SELECT `rates`.`cost`
FROM `rates`
INNER JOIN `teamMemberGrades` ON `rates`.`id` = `teamMemberGrades`.`rateId`
AND `teamMemberGrades`.`teamMemberId` = `planDays`.`teamMemberId`
WHERE `teamMemberGrades`.`startDate` IS NULL
OR `planDays`.`day` >= `teamMemberGrades`.`startDate`
ORDER BY `teamMemberGrades`.`startDate` DESC LIMIT 1)), 2) AS `value`
/**
* Autocomplete editor that can store a value separately to its displayed
* value. Uses a "handsontable-in-handsontable" editor.
*
* Requires the following configuration:
*
* - `source`, an array of arrays or a function that takes `query` and
* `callback` parameters like the one used by `AutocompleteEditor`.
* The data passed should be an array of objects or array of arrays,
* akin to the `data` of a Handsontable instance.
loadReferenceData: function() {
var self = this;
return Promise.join(
self.getSharedUsers()
.then(function(sharedUsers) {
self.sharedUsers = sharedUsers;
}),
syncModels: function(model, collection, where, include, keep) {
var collectionItems = {}, // lookup: id -> item from client
toUpdate = {}, // lookup: id -> db model
toCreate = [], // models
toDelete = []; // models
include = include || [];
// keep track of models we are updating
collection.forEach(function(item) {
define([
'jquery',
'underscore',
'app/app',
'moment',
'numeral',
'app/utils/dateutils',
'jquery.handsontable',
'bootstrap.datepicker'
@optilude
optilude / index.jsx
Created February 7, 2015 19:32
Routing triggers action
var React = require('react');
var Router = require('./router');
var NavigationActionCreators = require('./navigation/navigationActionCreators');
Router.run(function(Handler, state) {
NavigationActionCreators.routerNavigate(Handler, state);
React.render(<Handler />, document.body);
});

I’m querying an issue tracking system for a set of issues

The way the data comes back, I know when the issue was created and when it was changed, so I can iterate over all lifetime events for all issues.

I want to do some calculations like “how many open issues were there in each of the weeks from the start of the project until today”

To do this, I’m creating a DataFrame, initially populated with NaNs, with a multi-index on all the days the project has been live and all the issues found (some of which won’t have existed for each day)

lifetime_days = pd.date_range(start_date, datetime.date.today())

issue_keys = sorted(map(lambda s: s.key, issues))

from .query import QueryManager
import pandas as pd
import numpy as np
class StatusTypes:
backlog = 'backlog'
accepted = 'accepted'
complete = 'complete'
class CycleTimeQueries(QueryManager):
@optilude
optilude / jiraquery.py
Created August 6, 2015 22:18
jiraquery.py
# query.py
import itertools
import datetime
import dateutil.parser
import dateutil.tz
def to_datetime(date):
"""Turn a date into a datetime at midnight.
"""