Skip to content

Instantly share code, notes, and snippets.

@nixpulvis
nixpulvis / markdown.less
Created July 11, 2012 03:25 — forked from andyferra/github.css
Github Markdown CSS - for Markdown Editor Preview
.markdown {
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
def sieve( n )
s = (2..n).to_a
s.each { |p| next unless p; break if p**2 > n; (p**2).step(n, p) { |m| s[m-2] = nil } }
s.compact
end
def time
start = Time.now
yield
Time.now - start
@nixpulvis
nixpulvis / chain_assignment.rb
Created August 21, 2012 17:50
Sexy Chain Assignment
sum += e *= month_days[i]
@nixpulvis
nixpulvis / easyjava
Created September 10, 2012 05:24
Simple and Easy way to run a java class.
#!/usr/bin/env ruby
# ## An Easy Way to Compile and Run Java Classes
#
# System utility for compiling and running Java classes
# in a specific directory structure.
#
# #### Recommended Installation
# Save this code to a file named `easyjava`, somewhere on your HD. Then
# in your `~/.bash_profile` add the following:
@nixpulvis
nixpulvis / gist:3763424
Created September 21, 2012 19:33
quick and dirty assertEquals
private void assertEquals (String name, Object a, Object b) {
if (! a.equals(b)) {
System.out.println ("***** Test failed ***** "
+ name + ": " + totalTests);
System.out.println (" A => " + a);
System.out.println (" b => " + b);
totalErrors = totalErrors + 1;
}
totalTests = totalTests + 1;
}
@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