Skip to content

Instantly share code, notes, and snippets.

View kenkeiter's full-sized avatar
🦊

Ken Keiter kenkeiter

🦊
View GitHub Profile
@kenkeiter
kenkeiter / pyvirtualenv.rb
Created July 6, 2014 01:58
A quick Ruby wrapper for manipulating Python's virtual environments.
require 'open3'
class VirtualEnvError < Exception; end
class PythonVirtualEnv
def self.exists?(path)
File.directory?(path) and File.exists?(File.join(path, 'bin/activate'))
end
@kenkeiter
kenkeiter / rabl_patch.rb
Created July 17, 2014 02:18
If you're using Rabl with DataMapper, lazy collection queries won't be evaluated correctly, and you'll end up SELECTing each record from the database. This patch fixes that issue (albeit, in an ugly way).
module Rabl
class Engine
def collection(data, options={})
self.object(data_object(data))
end
end
module Helpers
def data_name(data_token)
@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 / 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 / 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 / vmware_driver.rb
Created May 9, 2011 15:06
Loose implementation of DC driver for Spherical
require 'deltacloud/base_driver'
require 'spherical'
module Deltacloud::Drivers::VMware
class VMwareDriver < Deltacloud::BaseDriver
# Configure hardware profile options
define_hardware_profile 'default' do
@kenkeiter
kenkeiter / image_placement.html
Created July 19, 2011 20:53
Place images atop other images
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>HTML5 boilerplate—all you really need…</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript" charset="utf-8">
@kenkeiter
kenkeiter / text-extents.js
Created August 28, 2011 19:14
JQuery zoom text to extents, supporting multiple inline spans.
;(function($){
$.fn.textExtents = function(options){
var spans = $('span:visible', this);
var heightMax = parseInt($(this).css('max-height'));
var widthMax = parseInt($(this).css('max-width'));
var fontSize = options.maxFontSizePx;
do{
var textHeight = 0;
var textWidth = 0;
$(spans).each(function(){