Skip to content

Instantly share code, notes, and snippets.

@lmaccherone
lmaccherone / divvyResources.coffee
Created January 25, 2012 02:34
Using ChartTime to divvy up Release resources across Iterations
{ChartTimeRange, ChartTime, ChartTimeIterator} = require('../src/ChartTime')
# Setting up the context
workDays = 'Monday, Tuesday, Wednesday, Thursday, Friday'
holidays = [
{month: 1, day: 1},
{month: 7, day: 4},
{month: 12, day: 25},
{year: 2012, month: 5, day: 28}
# Fill in the rest for your company if you want holidays taken into account
@lmaccherone
lmaccherone / Working-with-Dates-Times-and-Timezones-Top-10-Tips-for-Developers.markdown
Last active May 29, 2018 23:15
What's the correct query clause to get all the transactions from March on the east coast of the US? The correct answer is `"2012-03-01T05" <= eventTimestamp < "2012-04-01T04"`. Notice how the timeshift for the beginning of March is different from the end. Getting this right is mind bendingly difficult. This blog post and the Lumenize/tzTime libr…

Working with Dates, Times, and Timezones

Top 10 recommendations for developers

Update: tzTime (documentation) is now available seperately from Lumenize. The examples below still work because tzTime is a dependency of Lumenize and included in that package (as well as Rally's App SDK v2.0p6 or greater). However, Lumenize includes a lot more functionality around time-series and temporal model aggregations, OLAP Cube, etc. If you just want the Time object, just grab tzTime.

What's the correct query clause to get all the transactions from March? The naive answer is "2012-03-01" &lt;= eventTimestamp &lt;= "2012-03-31" but what if the person worked in the eastern US and wanted timezone taken into account? Then the correct answer is "2012-03-01T05" &lt;= eventTimestamp &lt; "2012-04-01T04". Notice how the timeshift for the beginning of March is different from the end. Getting this right is mind bendingly di

@lmaccherone
lmaccherone / assignmentA.md
Last active December 17, 2015 20:29
Lumenize programming assignments

Assignment A: functions

We have a functions "module" that contains a number of functions. We want to add a sumCubes function. Start by looking at the code for functions.sum and functions.sumSquares. Go take a look at functions.sumSquares(). The code for sumCubes will be very similar but instead of summing the raw values (temp += v), or the square of the values (temp += v * v), this will sum the cube (temp += v * v * v). Note: temp += v is short hand for temp = temp + v.

Lumenize.functions are designed to incrementally calculate the results from prior results. Did you notice how that works? The trick is to understand that in CoffeeScript it is perfectly legal to call a function with less than the full list of parameters. So, if you call functions.sum([1, 2, 3, 4]) (only using the fist values parameter), the answer will be 10. However, let's say you previously calculated the sum for [1, 2, 3] = 6 and you wanted to take advantage of that prior calculation to speed up the calculation of sum of

<!doctype html>
<html>
<head>
<meta charset='utf8'>
<meta name='viewport' content='width=device-width'>
<title>MatrX-Radar example</title>
<link rel='stylesheet' href='styles.css'>
async fetch(request) {
await this.hydrate()
const url = new URL(request.url)
if (url.search === '') {
return new Response(this.greeting)
} else {
this.name = url.searchParams.get('name')
this.state.storage.put('name', this.name)
this.greeting = `${this.state.id.toString()}: `
+ `Your name is ${this.name}. HELLO ${this.name.toUpperCase()}!`
import { TransactionalDOWrapperBase } from '@transformation-dev/cloudflare-do-utils'
export class OriginalGreeter {
async hydrate() {
if (this.hydrated) return
this.name = await this.state.storage.get('name')
this.greeting = await this.state.storage.get('greeting')
this.hydrated = true
}
export class TransactionalDOWrapperBase {
constructor(state, env) {
this.state = state
this.env = env
this.classInstance = null
}
async fetch(request) {
let response
try {
hydrate() {
if (this.hydrated) {
return Promise.resolve()
}
if (this._hydrating) {
return this._hydrating
}
// This assigns the promise SYNCHRONOUSLY within the method call, which
async function addCryptoToEnv(env) {
if (globalThis.crypto == null) {
try {
env.crypto = await import('crypto')
} catch (err) {
throw new Error('crypto support not available!')
}
} else {
env.crypto = globalThis.crypto
}
export class LazyHydrateDemo {
async hydrate() {
if (this.hydrated) return
this.value = await this.state.storage.get('value') ?? 0
this.hydrated = true
}
constructor(state, env) {
this.state = state
this.env = env