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
| # Note, this is getting run from a Rails console. | |
| # The results are a bit surprising. | |
| t = User.last.attributes.to_a.transpose | |
| # This returns an Array with 2 sub-arrays containing all attribute keys and values respectively | |
| # => [["work_phone", ... ], ["12345678910", ...]] | |
| Hash[t[0].zip(t[1])] == User.last.attributes | |
| # => true | |
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
| # Ubuntu 11.10 Setup Notes: | |
| # Note, this isn't really a script, i just called it .sh to get syntax highlighting | |
| # prep | |
| sudo apt-get update | |
| # setup git and ssh | |
| # Add key to github. | |
| ssh-keygen |
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
| class IfconfigParser | |
| MAC_REGEX = /^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/ | |
| # NOTE: this has some slightly weird results for wlan interfaces. Really meant to be used for eth0 | |
| def self.ifconfig(iface) | |
| output = Hash.new | |
| ifconfig_string = `ifconfig #{ iface }` | |
| ifconfig_string.gsub!("RX ", "RX_") | |
| ifconfig_string.gsub!("TX ", "TX_") |
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
| VALID_IP_ADDRESS = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/ | |
| VALID_HOSTNAME = /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/ |
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
| # Multi-value hashes in Ruby | |
| # Posted on March 24, 2011 | |
| # http://matthew.mceachen.us/blog/multi-value-hashes-in-ruby-1114.html | |
| # Any non-trivial project quickly finds itself needing data structures that are more exotic than simple arrays or maps. In my quest for multimap | |
| # nirvana, I first found references where every value-put call would need to be changed to look like this: | |
| h = {} | |
| (h[:key] ||= []) << "value 1" | |
| (h[:key] ||= []) << "value 2" | |
| puts h |
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
| <!DOCTYPE html> | |
| <!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ --> | |
| <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> | |
| <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]--> | |
| <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]--> | |
| <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> | |
| <head> | |
| <meta charset="utf-8" /> |
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
| #!/bin/sh | |
| # This checks that the specified file is less than 4 days old | |
| # deletes files that are too old | |
| for f in *.jpg | |
| do | |
| FILE=$f | |
| MAXAGE=$(bc <<< '4*24*60*60') # seconds in a week | |
| #MAXAGE=$(bc <<< '60') # seconds in a minute, for testing |
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
| class Application < Sinatra:: Base | |
| def initialize | |
| @xinstance = 'first' | |
| super | |
| end | |
| get '/1' do | |
| @xinstance = "hit 1" | |
| # returns "hit 1" |
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 'rubygems' | |
| require 'sinatra' | |
| require 'pry' | |
| # run with: | |
| # ruby params.rb | |
| # test route example: http://localhost:4567/blah/blee!!;;; | |
| get '/:test/:test2' do | |
| sanitize_params |
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 'rubygems' | |
| require 'net/ssh' | |
| # Run this on the machine (node) which needs to tunnel out to forward the UI to the remote system (console) | |
| Net::SSH.start("remote_host", "remote_user") do |ssh| | |
| # since we are running sinatra locally we will forward 43210 on the remote_host to our localhost 4567 | |
| # This is effectively the same as: | |
| # ssh -R 4567:localhost:43210 remote_user@remote_host | |
| ssh.forward.remote(4567, "localhost", 43210) | |
| ssh.loop { true } |