Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am justinweiss on github.
* I am justinweiss (https://keybase.io/justinweiss) on keybase.
* I have a public key whose fingerprint is 6FF0 E872 CACA 2A9A 8942 95E3 08F4 4018 35C2 8D55
To claim this, I am signing this object:
@justinweiss
justinweiss / init.el
Created November 4, 2008 21:11
get git root directory
(defun my-git-root ()
(let* ((current-directory (file-name-directory buffer-file-name))
(git-directory (concat current-directory ".git")))
(while (and
current-directory
(not (file-exists-p git-directory)))
(setq current-directory (file-name-directory (substring current-directory 0 -1)))
(setq git-directory (concat current-directory ".git")))
current-directory))
def book_with_endorsements(endorsement_count)
book = Factory(:book)
endorsement_count.times do |n|
Factory(:endorsement, :book_id => book.id)
end
book
end
@justinweiss
justinweiss / DefaultKeyBinding.dict
Created May 19, 2011 16:17
Extra emacs keybindings in cocoa.
/* Picked up from Help search on Key Bindings. Good stuff -shane */
/* ~/Library/KeyBindings/DefaultKeyBinding.dict */
{
"~f"="moveWordForward:";
"~b"="moveWordBackward:";
"~<"="moveToBeginningOfDocument:";
"~>"="moveToEndOfDocument:";
"~v"="pageUp:";
"~d"="deleteWordForward:";
"~^h"="deleteWordBackward:";
module HashExtensions
def string_merge(other, separator = " ")
merge(other) {|key, old, new| old.to_s + separator + new.to_s}
end
end
@justinweiss
justinweiss / tiny_object_model.rb
Last active November 11, 2016 18:38
Sample code from my "Metaprogramming? Not Good Enough!" RubyConf 2016 talk.
# We'll start by inheriting from a BasicObject, with our two properties: state and behavior.
class TinyObject < BasicObject
attr_accessor :state
attr_accessor :behavior
end
# `add_method`, for adding a method implementation to a behavior / class's state.
behavior_add_method = lambda do |behavior, method_name, method|
behavior.state[:methods][method_name] = method
@justinweiss
justinweiss / npm-publish-fork
Last active September 6, 2019 16:13
Publish a version of an npm package to your own scope, without (permanently) changing package.json
#!/usr/bin/env ruby
require "json"
require "optparse"
$options = {}
def system!(*args)
puts "> #{args.join(" ")}"
system(*args) || raise("Error running #{args.join(" ")}: #{$?} ")
@justinweiss
justinweiss / settings.rb
Created May 27, 2014 16:54
Simple settings for Rails
require 'yaml'
require 'erb'
require 'ostruct'
class Settings < OpenStruct
# Settings.new(:google_analytics)
def initialize(config_file_base_name)
super(YAML.load(ERB.new(File.read(Rails.root.join("config", "#{config_file_base_name}.yml"))).result)[Rails.env])
end
@justinweiss
justinweiss / filterable.rb
Last active January 11, 2024 07:28
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
@justinweiss
justinweiss / 0001-iio-imu-Add-driver-for-Bosch-BMI260-IMU.patch
Last active February 18, 2024 17:36
0001-iio-imu-Add-driver-for-Bosch-BMI260-IMU.patch
From 3f6507504828019e2812df1d7930d782e2ddeb23 Mon Sep 17 00:00:00 2001
From: Justin Weiss <justin@justinweiss.com>
Date: Tue, 13 Feb 2024 21:28:09 -0800
Subject: [PATCH] iio: imu: Add driver for Bosch BMI260 IMU
The ultra-low power BMI260 is an IMU consisting of a 16-bit tri-axial
gyroscope and a 16-bit tri-axial accelerometer combining precise
acceleration, angular rate measurement and intelligent on-chip
motion-triggered interrupt features.