Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / cli.rb
Last active November 9, 2017 17:50
CLI class that doesn't suck
class CLI
private
attr_accessor :flags
# Sexy Options #
################
def self.parse_flags
ARGV.each_with_index do |arg, i|
@nixpulvis
nixpulvis / evil.rb
Last active November 9, 2017 17:49
Evil... (this is what happens during a boring lecture)
Process.daemon; loop { fork { a=[]; loop { a<<(1..1000).inject(:*) || 1 }}}
@nixpulvis
nixpulvis / colorize.rb
Last active May 31, 2018 15:05
Colorize terminal output with ease.
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
def black; self.colorize(30); end
def red; self.colorize(31); end
def green; self.colorize(32); end
def yellow; self.colorize(33); end
@nixpulvis
nixpulvis / battery.rb
Created November 28, 2012 08:03
Ruby Mac Battery Display
#!/usr/bin/ruby
# encoding: utf-8
# Mac OS X Battery Display
#
# ▐▐▐▐▐▐▐▐▐▐
#
# by Nathan Lilienthal <nathanl@ccs.neu.edu> 2012
# Distributed under the GNU General Public License, version 3.0.
#
@nixpulvis
nixpulvis / get_if.rb
Created December 17, 2012 05:37
get_if for arrays.
class Array
# Return the first element where the given block returns true for.
def get_if
each { |v| return v if yield v }
return false
end
end
@nixpulvis
nixpulvis / dynamic_class_instantiation.rb
Created December 19, 2012 04:25
What I've come up with playing around trying to dynamically instantiate a class based on input. For example create a Car class if the name of the vehicle is a car's name.
module Vehicle
@@catigories = {
car: ["Focus", "Dart", "Civic"],
truck: ["F150", "Super Duty"],
van: ["Caravan", "Town and Country"],
}
def self.category(name)
@@catigories.each do |k,v|
@nixpulvis
nixpulvis / detrailer.rb
Created January 5, 2013 05:34
normalize my code files.
#!/usr/bin/env ruby
# Detrail.rb (remove all the damn trailing whitespace)
# because god hates people that leave trailing whitespace,
# don't use \n and use \t
#
# Usage:
# detrail (will assume current directory)
# detrail path/to/folder or/directory
#
@nixpulvis
nixpulvis / install_ruby.sh
Last active December 12, 2015 03:28
Entry point for an automated build on ubuntu.
# Get needed packages as root
sudo apt-get -q update
sudo apt-get install -qy build-essential openssl libreadline6 \
libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev \
libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev \
ncurses-dev automake libtool bison pkg-config libffi-dev
sudo apt-get install -qy libqt4-dev # for capybara-webkit
sudo apt-get install -qy libpq-dev # for pg
@nixpulvis
nixpulvis / logging.sh
Last active December 12, 2015 06:49
shell logging
# Color escapes
RESET="\e[0m"
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
LOGFILE_DIR="$HOME"
DATETIME=`date "+%m_%d_%Y_%H.%M.%S"`
LOGFILE="$LOGFILE_DIR/build_$DATETIME.log"
touch $LOGFILE
@nixpulvis
nixpulvis / badness.rb
Created February 12, 2013 18:35
The worst 3 line I've ever written, that also works.
s = options[:sudo].nil? ? sudo? || dependency.sudo? : options[:sudo]
f = options[:flags].nil? ? "#{flags+' ' if flags}#{dependency.flags}" : options[:flags]
system "#{'sudo ' if s}#{program} #{command} #{f+' ' unless f.to_s == ''}#{dependency}"