Skip to content

Instantly share code, notes, and snippets.

View jaz303's full-sized avatar

Jason Frame jaz303

  • Glasgow, Scotland, UK
  • 18:00 (UTC +01:00)
View GitHub Profile
@jaz303
jaz303 / gist:e4e3bc9c5667259c3bcc5267763e2464
Last active May 10, 2016 11:28
Integrating distance with damping

I'm trying to calculate the total distance travelled by an object with a known initial velocity and a damping factor that is applied to the velocity at each timestep. The iterative solution is easy:

// timestep and damping are constant
// v is velocity
// d is total distance
while (Math.abs(v) > 0.001) {
	d += timestep * v;
	v *= damping;
}
// I assume this is horribly illegal but it seems to work!
// NB. array size is fixed at creation time; it will never change.
// Also... source array is class instance variable.
func cast<T>(inout ary: Array<UInt8>) -> UnsafeMutablePointer<T> {
var ptr: COpaquePointer = nil
ary.withUnsafeMutableBufferPointer { (tmp) in
ptr = COpaquePointer(tmp.baseAddress)
}
return UnsafeMutablePointer<T>(ptr)
}

You need 3 USB sticks; one each for OS X, Linux, Windows.

  1. BACK UP YOUR SHIT FIRST
  2. start with a fresh install of OS X
  3. initiate bootcamp; create USB from Windows 10 ISO + download Apple drivers
  4. set bootcamp partition to total size for windows + linux
  5. intercept windows installer by restarting with option key held down, boot back into OS X
  6. open disk utility
  7. reformat bootcamp partition as mac partition (so it can be resized)
  8. decrease size of bootcamp partition to leave space at end for Linux
@jaz303
jaz303 / halp.ts
Last active December 1, 2015 18:16
Is this a bug?
type GeometryUnion = Circle | Rectangle | Polygon | PolyLine;
// This does not compile, the error is:
// error TS2339: Property 'center' does not exist on type 'Circle | Rectangle | Polygon | PolyLine'
class GeometryItem {
name: string;
object: GeometryUnion;
children: GeometryItem[];
constructor(name : string, object : GeometryUnion) {
this.name = name;
#define _XOPEN_SOURCE
#include <ucontext.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
// If I make this 16KiB the program crashes. why?
#define STACK_SIZE (32 * 1024)
void task(int);

So I have some time series data, potentially lots of it - 10-100M+ items.

The schema is roughly:

  • timestamp: datetime of event
  • value: float value of event
  • source_id: the "thing" that generated this data
  • zone_id: the container in which source_id is located

Data will be inserted into the store in arbitrary order.

function Animation() {
this.startTime = null;
this.endTime = null;
this.duration = null;
this.ease = null;
this.apply = null;
var self = this;
this._resolve = null;
this._promise = new Promise(function(resolve) {
package job
import (
"bufio"
"fmt"
"github.com/op/go-logging"
"hash/fnv"
"os"
"time"
)

In this scenario, there is a single pool of combined workers/content servers, and each of these machines is authoritative for a given set of sites (probably determined by some sort of consistent hash). A dynamic reverse proxy is responsible for dispatching each incoming request to the correct worker machine based on the request hostname/path.

Plan 1

Pros

  • simple
  • exactly one machine is authoritative for each site, so no need for distributed locking (in-process lock is sufficient)
@jaz303
jaz303 / gist:516ba350fe9c00293036
Created March 2, 2015 11:25
Is there a better way to write this?
var publisherUsername string
var username string
var projectName string
var archiveType string
var archivePath string
var timeReceived string
if publisherUsername, err = readLine(); err != nil { return nil, err }
if username, err = readLine(); err != nil { return nil, err }
if projectName, err = readLine(); err != nil { return nil, err }