Skip to content

Instantly share code, notes, and snippets.

View albertosaurus's full-sized avatar

Arthur Shagall albertosaurus

  • Mindflight, Inc.
View GitHub Profile
@albertosaurus
albertosaurus / list_off_tree_modules.sh
Created March 11, 2018 00:58
List off-tree linux kernel modules
#!/bin/bash
locate --null "*lib/modules/$(uname -r)*" | xargs -r0 sh -c 'for i do [ -d "$i" ] && printf "%s\n" "$i"; done' sh {} + | grep -v "^/lib/modules/$(uname -r)/kernel\|^/lib/modules/$(uname -r)$\|^/lib/modules/$(uname -r)/build$\|^/lib/modules/$(uname -r)/initrd$" | xargs ls
@albertosaurus
albertosaurus / compute_focal_length.rb
Last active October 22, 2016 05:54
Ruby script to calculate actual focal length at minimum focusing distance (mm) and max reproduction ratio
# Pretty much all consumer lenses suffer from focus breathing at close distances, i.e the focal length changes.
# This lets us calculate the max focal length of a given lens at minimum focusing distance.
#
# Example 1: Nikon 70-200 f2.8 VR II - minimum focusing distance is 1.4m, max reproduction ratio is 0.12x.
#
# compute_focal_length 1400, 0.12
# => 133.92857142857142
#
# So at close distances, the Nikon isn't a 200mm lens, it's more like 135mm.
#
@albertosaurus
albertosaurus / transaction_trick.rb
Last active November 22, 2021 17:12
Rails programming trick - macro to wrap a method call in a transaction
module WithTransaction
extend ActiveSupport::Concern
module ClassMethods
# Wrap the given method in a transaction.
def with_transaction(method_name)
define_method "#{method_name}_with_transaction" do |*args, &block|
@albertosaurus
albertosaurus / rubygems_1.8.8_jruby_1.6.3_gem_install_failure
Created August 18, 2011 16:07
rubygems 1.8.8 jruby 1.6.3 gem install failure
~$ export JRUBY_OPTS=--1.9; gem install json --debug -V
GET http://rubygems.org/latest_specs.4.8.gz
302 Found
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
304 Not Modified
Installing gem json-1.5.3-java
ERROR: While executing gem ... (ArgumentError)
wrong number of arguments (2 for 1)
/home/arthur/bin/jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_input.rb:57:in `initialize'
/home/arthur/bin/jruby/lib/ruby/site_ruby/1.8/rubygems/package/tar_reader.rb:64:in `each'
@albertosaurus
albertosaurus / gem_env_rubygems_1.8.8_jruby_1.6.3
Created August 18, 2011 16:05
gem env rubygems 1.8.8 jruby 1.6.3
~$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.8
- RUBY VERSION: 1.9.2 (2011-07-07 patchlevel 136) [java]
- INSTALLATION DIRECTORY: /home/arthur/bin/jruby-1.6.3/lib/ruby/gems/1.9
- RUBY EXECUTABLE: /home/arthur/bin/jruby/bin/jruby
- EXECUTABLE DIRECTORY: /home/arthur/bin/jruby/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-java-1.6