Skip to content

Instantly share code, notes, and snippets.

@sneakin
sneakin / bonnet.dts
Created September 11, 2018 06:53
Overlay for Adafruit's OLED Bonnet https://www.adafruit.com/product/3531
//!/usr/bin/dtc -I dts -O dtb -o bonnet.dtbo bonnet.dts
// Overlay for Adafruit's OLED Bonnet https://www.adafruit.com/product/3531
// May need to add "fbcon=map:1" to /boot/cmdline.txt
/dts-v1/;
/plugin/;
/ {
compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
@sneakin
sneakin / uptime.rb
Last active December 14, 2015 00:29
Display loadavg and memory usage as a textual bar graph suitable for Tmux's statusbar: █▄▃ ▁█
#!/usr/bin/ruby
module LinuxProcInfo
def self.cpucount
File.readlines("/proc/cpuinfo").find_all { |s| s.start_with?('processor') }.count
end
def self.loadavg
File.read('/proc/loadavg').split[0, 3].collect(&:to_f)
end
@sneakin
sneakin / .gitignore
Last active December 10, 2015 23:59
A very basic Unix shell using #method_missing.
*~
TODO.html
@sneakin
sneakin / gist:1292579
Created October 17, 2011 13:12
jRuby IO.select fail
# This should print "nada" unless stdin has data.
while true
i, o, e = IO.select([$stdin], nil, nil, 0)
if i.include?($stdin)
c = $stdin.readpartial(1024)
puts c.inspect
else
puts "nada"
@sneakin
sneakin / console_parser_test.erb
Created September 25, 2011 05:05
ERB and C++
#include "console_parser.hpp"
class ConsoleParserTest: public CxxTest::TestSuite
{
public:
class Callback: public ConsoleParser::CommandCallback
{
public:
bool called;
int argc;
@sneakin
sneakin / myfs.rb
Created September 17, 2011 17:51
A super basic RFuse file system.
#!/usr/bin/env ruby
#
# Minus the logging, this is the simplest file system that's most likely
# possible with RFuse-NG. It presents a single directory level that stores
# the contents of files in a Hash.
#
# This is in the public domain.
#
# Enjoy,
# sneakin
@sneakin
sneakin / beauty.rb
Created March 19, 2011 10:39
Something beautiful
class Foo
def bar
baz # is it a method, an attribute, or a local variable
end
end
@sneakin
sneakin / ensure.rb
Created December 23, 2010 03:32
Example where an ensure clause will prevent exceptions from being raised.
def wont_raise
raise "Catch me if you can"
ensure
puts "ensured"
return "HA"
end
def will_raise
raise "Caught me"
ensure
require 'spec'
require 'active_support'
class Rule < Struct.new(:quantity, :price)
def apply(number)
[ number / quantity * price, number % quantity ]
end
end
class CheckOut < Struct.new(:rules, :items)
Scenario: happy path
When I send "connect alice password"
Then I see
"""
Hello alice! For help, enter "/help".
"""
And I see "You are standing in the mud."
And I see "There is a helicopter a click to your six and two crates a yard ahead."
And I see "Direction: east"
And the people I see are: alice