Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# From: https://apple.stackexchange.com/questions/415355/is-it-possible-to-detect-the-current-power-input-on-a-macbook
ioreg -rw0 -c AppleSmartBattery |
grep BatteryData |
grep -o '"AdapterPower"=[0-9]*' |
cut -c 16- |
xargs -I % lldb --batch -o "print/f %" |
grep -o '[0-9.]*' |

Keybase proof

I hereby claim:

  • I am mrjoy on github.
  • I am mrjoy (https://keybase.io/mrjoy) on keybase.
  • I have a public key ASCSMavqX1FtBCrvHXWxYlh3yHdMp97Mjfqrebip28Allgo

To claim this, I am signing this object:

@MrJoy
MrJoy / example.rb
Created April 17, 2014 20:54
Make the constructor private in Ruby.
class Example
class << self
def my_alternative_constructor
# From here you can call .new, and do fun things like say, call .freeze before returning the instance.
return Example.new.freeze
end
protected
alias_method :private_new, :new
@MrJoy
MrJoy / git_ls_files.rb
Created October 10, 2012 22:42
A VERY partial implementation of .gitignore semantics in Ruby...
#!/usr/bin/env ruby
require 'set'
# This code is meant to demonstrate the difficulty of actually applying .gitignore semantics manually. It supports a key subset of .gitignore
# behaviors, including:
# * Anchored and unanchored patterns/globs.
# * Un-ignoring of patterns/globs, with the same quirky semantics as git.
# * Escaping a leading hash in a pattern.
# * User-wide exclusion list.
# * Top-of-repo .gitignore.
@MrJoy
MrJoy / bspack.sh
Created September 21, 2012 22:33
Insane compression for consecutive snapshots of things...
#!/bin/bash
DIR=$1
DIR=${DIR%/}
if [ -d "$DIR" ]; then
pushd "$DIR" > /dev/null 2>&1
ls *.yml | sort -n > infiles.txt
cat infiles.txt | while read FNAME; do
BASIS=$(grep -E -B 1 "^$FNAME\$" infiles.txt | grep -v $FNAME)
if [ "$BASIS" != "" ]; then
echo "Creating diff between $BASIS and $FNAME..."
@MrJoy
MrJoy / bwt.rb
Created September 20, 2012 03:26
Core of my Burrows-Wheeler Transform code.
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
Bundler.setup(:default, :development)
###############################################################################
# Burrows-Wheeler Transform
###############################################################################
class BurrowsWheelerTransform
BLOCK_SIZE = 256