Skip to content

Instantly share code, notes, and snippets.

View kenkeiter's full-sized avatar
🦊

Ken Keiter kenkeiter

🦊
View GitHub Profile
@kenkeiter
kenkeiter / text_extents.js
Created July 12, 2012 22:30
Resize text to fit a min/max.
;(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 = parseInt($(this).css('font-size')); /* max font size */
do{
var textHeight = 0;
var textWidth = 0;
$(spans).each(function(){
@kenkeiter
kenkeiter / grapeish.rb
Last active December 10, 2015 02:38
Fix grape's incredible brokenness.
require 'sinatra/base'
require 'sinatra/namespace'
# You may need multi_json
class API < Sinatra::Base
# Respond to all errors with JSON
error do
content_type :json
e = env['sinatra.error']
@kenkeiter
kenkeiter / Nested resources.coffee
Created March 15, 2013 20:49
Coffee script nested resources example (may or may not be working -- kind of pseudo-code).
class User extends Spine.Model
url: ->
'/' + @username
collections: ->
unless @collection_klass?
@collection_klass = _.clone(Collection)
@collection_klass.parent = this
@collection_klass
@kenkeiter
kenkeiter / config.ru
Last active December 17, 2015 06:18
If you've tried to mount RESTful resources at '/' with Padrino, you've probably run into issues with its router, and had to :map each action (or develop some idiom to generate the mappings for you). Padrino's router is pretty opinionated; when you're using named controllers, you'll want to make use of `:parent` directives -- which you can't, if …
# You'll need to add 'rack-rewrite' to your Gemfile.
require 'rack/rewrite'
require File.expand_path("../config/boot.rb", __FILE__)
# lazy load the application, instantiating routes.
application = Padrino.application
# Determine which routes NOT to redirect to your root resource.
reserved_routes = YourProject::App.routes.map{|r|
r.path_for_generation.scan /[a-zA-Z0-9]+/i
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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>
.js-moments-tab {
display: none !important;
}
.wtf-module {
display: none !important;
}
.LiveVideoHomePageModuleContainer {
display: none !important;
@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
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 / 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>