Skip to content

Instantly share code, notes, and snippets.

View coffeeaddict's full-sized avatar

Hartog C. de Mik coffeeaddict

View GitHub Profile
@coffeeaddict
coffeeaddict / battery.rb
Created April 16, 2014 07:33
Battery stats
#!/usr/bin/env ruby
#
# Read battery event file and return some numbers
require 'json'
stats = {}
File.open("/sys/class/power_supply/BAT1/uevent", File::RDONLY) do |f|
while(line = f.gets)
(key, value) = line.chomp.split('=')
#!/usr/bin/env ruby
require 'open3'
begin
stdout, status = Open3.capture2("git status -uno --porcelain")
rescue Errno::ENOENT
abort "Cannot run `git status -uno --porcelain`."
end
@coffeeaddict
coffeeaddict / Bar.pm
Created June 15, 2009 12:14
Mocking about with DESTROY 4 eelkonio
package Bar;
use strict;
sub new {
my $class = ref($_[0]) || $_[0]; shift;
return bless({}, $class);
}
@coffeeaddict
coffeeaddict / exceptions.rb
Created October 19, 2009 07:07
it does work
module Exceptions
# custom exceptions / errors with custom default messages a-go-go
# the base for defined errors.
class DefinedError < RuntimeError
@msg = "Undefined Defined Error"
def message
return @msg || super
#!/usr/bin/perl -l
#
# hartog/20100311: break down a WSDL into a list of functions with
# input and output nicely tucked in.
#
# install the perl modules below, put this in your
# cgi-bin and get going.
#
# wouldn't be using this in a public space as it
# might consume a lot of resources...
class Foo
# same as attr_accessor :variant
def variant
return @variant
end
def variant=(arg)
@variant = arg
end
# make an alternative for send_later that accepts a run_at time
#
module Delayed
module MessageSending
def send_later_at(at, method, *args)
Delayed::Job.enqueue(
Delayed::PerformableMethod.new(self, method.to_sym, args),
0, #priority
at #run_at
)
@coffeeaddict
coffeeaddict / passphrase_generator.rb
Created August 23, 2010 19:07
Generate passwords
class PassphraseGenerator
WORDS_LIST = "/usr/share/dict/words"
@@words = nil
CONJUNCTIONS = %w(and or but you me we him + the -)
FUZZ = %w(! @ # $ % ^ & * - + ~ ` , . < > / ?);
# make a phrase of two words and a conjuction
#
# fuzz the words and return the fuzzed phrase and the original phrase
#
class CreateprogramDependencies < ActiveRecord::Migration
def self.up
create_table :program_dependencies do |t|
t.references :dependency, :polymorphic => true
t.references :program
end
end
def self.down
drop_table :program_dependencies
@coffeeaddict
coffeeaddict / i18n_scoped.rb
Created October 21, 2010 10:21
Scopes for I18n
# = I18n scoped
#
# Set a temporal default scope for I18n
#
# == Synopsis
#
# Given a locale YAML that looks like this:
#
# customers:
# firstname: Customer firstname