This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Core extension: | |
# Shortcut to a full file path | |
# ala: require File.pwd + '/some/other/file' | |
# Fixed naive, untested version per dradcliffe. Thanks! | |
class File | |
def self.pwd | |
self.expand_path(self.dirname(caller.first.split(':').first)) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Contribution to Rake::Task to allow for reseting the known invoked state. | |
# Sometimes you have a complicated Rake setup and looping constructs inside of | |
# an executing rake task make sense. | |
# - jodell 20090413 | |
# | |
class Rake::Task | |
attr_accessor :already_invoked |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Parsing Expression Grammar for basic boolean logic on a set of k -> { v1, v2, ... } elements. | |
# Amazing talk about Treetop and PEG's: http://rubyconf2007.confreaks.com/d1t1p5_treetop.html | |
# | |
# lst = { | |
# 'foo' => [1, 2], | |
# 'bar' => [2, 3, 4], | |
# 'baz' => [5, 6] | |
# } | |
# | |
# require 'treetop' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Given a key/value list of nodes and their children, this returns the reversed, | |
# breadth-first search, the driving need of which is to find the build order of | |
# applying seed tables and their dependencies. | |
# | |
# - jodell 20080530 | |
# | |
def reverse_bfs(list, nodes = []) | |
return nodes unless nodes.any? { |v| not list[v].nil? } | |
return reverse_bfs( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash BAH | |
# Simple enumeration | |
for i in $(seq 1 30); do convert ${i}.jpg -resize 90x90 ${i}_90x90.jpg; done | |
# find/sed/xargs example | |
# sed here trims all preceding /path/to/foo values (effectively same as basename) | |
find . -name "mef.*" | sed 's!.*/!!' | xargs -o -I file p4 integ file ~/p4/db/seed/CA/file | |
# better find/xargs example eliminating need for sed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Automatically apply security updates, resets to normal repo listings, | |
# and downloads packages ahead of time for manual upgrades. | |
# This is necessary if you're running Ubuntu (always unstable), have | |
# custom repos that you might not want to auto-update from, etc. | |
# Cron'ing this script helps ward off auditors and cyber-ninjas alike. | |
# -jodell 20100115 | |
# Assumes that you've partitioned security repo lines appropriately | |
sudo apt-get -o "Dir::Etc::SourceList=/etc/apt/security.list" -o "Dir::Etc::sourceparts=''" update |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VI MAGIC | |
# NOTE: Why am I using hash comments? | |
# Courtesy of bfeigin: | |
# "found this little nugget, great whenever you edit a root owned config file but forget to sudo before hand" | |
:w !sudo tee % |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns a random item from a hash of key => weight | |
# -jodell 20100321 | |
def select_weighted(hsh) | |
# roll randomly on the sum of values | |
roll = rand(hsh.values.inject(0) { |sum, v| sum += v }) | |
index = 0 | |
hsh.each do |k, v| | |
index += v | |
return k if index > roll | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fcntl' | |
# http://blog.footle.org/2008/08/21/checking-for-stdin-inruby/ | |
@stdin = STDIN.read if STDIN.fcntl(Fcntl::F_GETFL, 0) == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface spodViewController : UIViewController <UIAccelerometerDelegate, MFMailComposeViewControllerDelegate> { | |
// Example of implementing more than one protocol | |
// USE COMMAS! | |
} |
OlderNewer