Skip to content

Instantly share code, notes, and snippets.

View kenkeiter's full-sized avatar
🦊

Ken Keiter kenkeiter

🦊
View GitHub Profile
@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;
@kenkeiter
kenkeiter / kicad6_arrange.py
Last active July 6, 2022 16:52
KiCAD 6 Script for arranging footprints circularly
import pcbnew
import math
# Based upon https://bit.ly/3agYp7f by Greg Davill (@GregDavill on Twitter)
#
# To use this with KiCAD 6.x.x:
# 1. Save this script in KiCAD's "scripting/plugins" directory as "arrange.py"
# 2. Open your PCB and refresh plugins by navigating to
# Tools > External Plugins > Refresh Plugins
# 3. Open the scripting console (Tools > Scripting Console) and execute
@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)!,
@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 / markdown_to_pdf.py
Created October 17, 2019 17:23
Quick markdown file to PDF routine.
import os
import markdown
from markdown_include.include import MarkdownInclude
import weasyprint
from mako.template import Template
HTML_BOILERPLATE_TEMPLATE = """
<html>
<head>
<style>{css}</style>
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
make \
file \
curl \
ca-certificates \
python2.7 \
git \
@kenkeiter
kenkeiter / guards.rb
Last active August 3, 2018 19:34
Guard-like things in Ruby
class Proc
def call_with_vars(vars, *args)
Struct.new(*vars.keys).new(*vars.values).instance_exec(*args, &self)
end
end
module Touchy
class GuardError < Exception; end
class GuardSignatureError < GuardError; end
.js-moments-tab {
display: none !important;
}
.wtf-module {
display: none !important;
}
.LiveVideoHomePageModuleContainer {
display: none !important;
@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>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.