Skip to content

Instantly share code, notes, and snippets.

View kenkeiter's full-sized avatar
🦊

Ken Keiter kenkeiter

🦊
View GitHub Profile
@kenkeiter
kenkeiter / rescue_nimbus.rb
Created August 20, 2014 14:52
Display RescueTime productivity on the Quirky Nimbus
require 'rest_client'
require 'json'
require 'pp'
class RescueTimeProfile
API_BASE_URL = 'https://www.rescuetime.com/anapi'
TIME_SCORE_SCALE = {
2 => 1,
@kenkeiter
kenkeiter / rescue_time.rb
Created August 25, 2014 22:37
Get your RescueTime productivity using Ruby and the RescueTime API.
require 'rest_client'
require 'json'
class RescueTimeProfile
API_BASE_URL = 'https://www.rescuetime.com/anapi'
TIME_SCORE_SCALE = {
2 => 1,
1 => 0.75,
0 => 0.50,
@kenkeiter
kenkeiter / go_marshaling_thoughts.md
Created October 5, 2014 16:41
Quick thoughts on separation of representation from implementation in Go serialization.

If your application demands marshaling to JSON or another serialiazation format using Go, it can be tempting to design your structures to be cleanly serializable – often to the detriment of the implementation.

You might find yourself exporting variables you shouldn't be exporting, or creating elaborate ways to prevent mutability of attributes you care about.

If you find yourself doing this, stop, and consider the separation of concerns. JSON is a representation of your structure, and should not be directly tied to its underlying implementation, unless it's convenient. Although it's a bit more expensive, consider creating custom marshaling functions and generating one-off structs with the exact fields you need to decouple the implementation from representation.

In the following example, you don't want to export the Value field from the Counter struct, because it exposes your value to potentially unsafe operations (two incrementations at the same time, for example):

type Counter struct {
@kenkeiter
kenkeiter / homebrew_yosemite_valgrind.txt
Created October 20, 2014 00:33
Homebrew output when building valgrind on Yosemite.
~ → brew install valgrind
valgrind: OS X Mavericks or older is required for stable.
Use `brew install devel or --HEAD` for newer.
Error: An unsatisfied requirement failed this build.
~ → brew edit valgrind
~ → brew install valgrind
==> Downloading http://valgrind.org/downloads/valgrind-3.10.0.tar.bz2
######################################################################## 100.0%
==> Downloading https://gist.githubusercontent.com/jacknagel/369bedc191e0a0795358/raw/a71e6c0fdcb786fdfde2fc33d71d555b18
######################################################################## 100.0%
@kenkeiter
kenkeiter / lmutracker.mm
Last active April 20, 2017 01:06
Read lux measurement using MBP ambient light sensor.
// lmutracker.mm -- Provides lux measurement using MacBook Ambient Light Sensor
//
// clang -o lmutracker lmutracker.mm -framework IOKit -framework CoreFoundation
//
// Adaptation of code originally posted at https://bugzilla.mozilla.org/show_bug.cgi?id=793728
// by Reuben Morais. Modified by Ken Keiter <ken@kenkeiter.com> to output a single *lux* value
// and exit, rather than repeating measurements on the sensor's arbitrary scale.
#include <mach/mach.h>
#include <math.h>
@kenkeiter
kenkeiter / storage.md
Last active August 29, 2015 14:14
Small + Low Power Storage for Max

Did my best to find a quick/cheap platform you can experiment with. This is an example of an underpowered SoC. Even though the board itself supports SATA 2.5, USB 3, and Gig-E, the CPU can't. Obviously, it doesn't fulfill your needs, but you can run benchmarks to figure out what you actually need based upon it.

@kenkeiter
kenkeiter / index.html
Last active August 29, 2015 14:19 — forked from bunkat/index.html
<!--
The MIT License (MIT)
Copyright (c) 2013 bill@bunkat.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@kenkeiter
kenkeiter / impbcopy.m
Last active January 17, 2024 23:02
Take a selfie, archive it, and copy it to the clipboard -- all from the terminal! (bash + os x)
/////////////////////////////////////////////////////////
// Copied from http://www.alecjacobson.com/weblog/?p=3816
/////////////////////////////////////////////////////////
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <unistd.h>
BOOL copy_to_clipboard(NSString *path)
{
// http://stackoverflow.com/questions/2681630/how-to-read-png-image-to-nsimage
NSImage * image;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kenkeiter
kenkeiter / hktypes.swift
Created April 15, 2017 16:25
A full set of all HKObjectTypes (excluding correlation types, as of Apr. 15, 2017) because typing this out was a pain in the ass.
let hkTypes:Set<HKObjectType> = [
// body measurements
HKObjectType.quantityType(forIdentifier: .bodyMassIndex)!,
HKObjectType.quantityType(forIdentifier: .bodyFatPercentage)!,
HKObjectType.quantityType(forIdentifier: .height)!,
HKObjectType.quantityType(forIdentifier: .bodyMass)!,
HKObjectType.quantityType(forIdentifier: .leanBodyMass)!,
// fitness identifiers
HKObjectType.quantityType(forIdentifier: .stepCount)!,
HKObjectType.quantityType(forIdentifier: .distanceWalkingRunning)!,