Skip to content

Instantly share code, notes, and snippets.

Trevor Phillips trevphil

Block or report user

Report or block trevphil

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
trevphil / spectre.c
Created Aug 1, 2019
Spectre attack implemented in C
View spectre.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#include <x86intrin.h> /* for rdtscp and clflush */
View CheckScenario.swift
func checkScenario(_ scenario: Scenario) {
let filter = KalmanFilter()
// Add up the distance between each location in the true path
let trueDist = unfilteredDistance(scenario.truePath)
// Add up the distance between each location in the noisy path
let unfilteredDist = unfilteredDistance(scenario.noisyPath)
trevphil / KalmanFilter.swift
Created Jun 3, 2019
Kalman Filter for CLLocation
View KalmanFilter.swift
import Foundation
import CoreLocation
extension CLLocation {
// Alias for `horizontalAccuracy` (more readable)
var uncertainty: Double {
return horizontalAccuracy
View Parameters.swift
enum PathType: String, CaseIterable {
case outAndBack, loop
enum Distance: Double, CaseIterable {
case short = 1000 // in meters
case medium = 5000
case long = 15000
trevphil / Scenario.swift
Last active Jun 3, 2019
Scenario Struct
View Scenario.swift
struct Scenario {
/// A sequence of CLLocations representing the "true path" of the GPS track
let truePath: [CLLocation]
/// A sequence of CLLocations based on the true path, but with noise added to various parameters
let noisyPath: [CLLocation]
/// A number between 0.0-1.0 representing the minimum allowable percentage difference between
trevphil / LocationConversion.swift
Last active Jun 3, 2019
True location to noisy location
View LocationConversion.swift
func addNoise(to trueLocation: CLLocation) -> CLLocation {
let distanceWiggle = sampleNormalDist(withMean: 0, std: 0.952)
let xContribution = rng.nextUniform()
let xoff = distanceWiggle * Double(xContribution)
let yoff = distanceWiggle * sqrt(1 - pow(Double(xContribution), 2))
let newCoord = trueLocation.coordinate.offsetBy(xMeters: xoff, yMeters: yoff)
let newHacc = sampleNormalDist(withMean: 7.179, std: 1.682)
let newVacc = sampleNormalDist(withMean: 3.643, std: 0.300)
let timeWiggle = sampleNormalDist(withMean: 1.00, std: 0.131)
trevphil / SampleNormalDist.swift
Last active Jun 3, 2019
Sampling from normal distribution
View SampleNormalDist.swift
private func sampleNormalDist(withMean mean: Double, std: Double) -> Double {
precondition(std > 0)
let first = Double(rng.nextUniform())
let second = Double(rng.nextUniform())
let zScore = sqrt(-2 * log(first)) * cos(2 * Double.pi * second)
return zScore * std + mean
trevphil /
Created Jun 3, 2019
Python helper to convert GPX data to CSV
Helper to convert GPX files to CSV files for analysis.
Created by Trevor Phillips
import os
import json
You can’t perform that action at this time.