Skip to content

Instantly share code, notes, and snippets.

View jodell's full-sized avatar

Jeffrey ODell jodell

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jodell on github.
  • I am jodell (https://keybase.io/jodell) on keybase.
  • I have a public key whose fingerprint is 5804 DCC2 C143 223A B290 A374 B8DF 254E 7DC1 4831

To claim this, I am signing this object:

@jodell
jodell / gist:11122578
Created April 20, 2014 19:15
Ruby Time Parsing
ti = Time.now.to_i
t = Time.now.to_s
2.0.0-p451 :015 > puts Benchmark.measure { 100_000.times { Time.at(ti) } }
0.030000 0.000000 0.030000 ( 0.041530)
=> nil
2.0.0-p451 :016 > puts Benchmark.measure { 100_000.times { Time.parse(t) } }
2.680000 0.070000 2.750000 ( 2.755467)
@jodell
jodell / File.rb
Created December 16, 2009 02:07
file_ext.rb
# 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
##
# 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
# 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'
##
# 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(
# 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
#!/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
# 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 %