Skip to content

Instantly share code, notes, and snippets.

@rockpapergoat
rockpapergoat / searchdoc.rb
Created March 21, 2012 02:56
scraping with nokogiri
#!/usr/bin/env ruby
require 'nokogiri'
doc = Nokogiri::HTML(open("test.html"))
doc.xpath('//div[@class="level"]/strong').each {|node| puts node.text}
doc.xpath('//div[@class="level"]').each {|node| puts node.text.strip}
@rockpapergoat
rockpapergoat / prefs.rb
Created March 7, 2012 01:39
getting and setting prefs from a plist in macruby
#!/usr/local/bin/macruby
# nb. http://stackoverflow.com/questions/8738424/macruby-how-to-create-an-app-that-can-be-configured-from-the-outside
framework 'Cocoa'
framework 'Foundation'
def set_prefs(pref)
if File.exists?(pref)
@config = load_plist File.read(pref)
@rockpapergoat
rockpapergoat / app_uninstall_install.rb
Created March 1, 2012 19:37
wrapper for jamf policy runner
#!/usr/bin/env ruby
# 110224, revised with loop to accept an array
# 110425, swapped order of variable definition in get_version
# 120301, made more generic, removed loop, added uninstall and install
require 'FileUtils'
def get_version(app)
if File.exists?("#{app}/Contents/Info.plist")
vers = `/usr/bin/defaults read "#{app}"/Contents/Info CFBundleShortVersionString`.chomp
#!/usr/bin/env ruby
# cf. http://puppetlabs.com/blog/facter-part-3-caching-and-ttl/
require 'rubygems'
require 'rest_client'
# if you're behind a proxy, define it here
RestClient.proxy = ""
geo_raw=(RestClient.post "http://api.hostip.info/get_html.php", :position=>"true")
geo_data=Hash[*geo_raw.scan(/(.*): (.*)\n/).to_a.flatten]
#!/usr/bin/env bash
function wireless_disable () {
version=`sw_vers -productVersion | cut -d "." -f 2`
airport=`networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/ {getline; print $2}'`
case $version in
"7" )
networksetup -setairportpower $airport off
echo "power to $airport is off."
;;
# in cacheController.py, around line 300
# add this to enable proxy support
# cf. http://stackoverflow.com/questions/1450132/proxy-with-urllib2
proxy_support = urllib2.ProxyHandler({"http" : "http://proxy.company.com:8080"})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
#
# Copyright 2009 Joe Block <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@rockpapergoat
rockpapergoat / stash_prefs.rb
Created January 24, 2012 21:50
copy user pref files
require 'FileUtils'
require 'pathname'
def stash_user_file(file)
users = get_users
users.each do |u|
if File.directory?(file)
if File.exist?("#{get_homedir(u)}/Library/Preferences/#{File.basename(file)}")
puts "copying files to #{u}\'s homedir."
system "/usr/bin/rsync -rv #{file}/ #{get_homedir(u)}/Library/Preferences/#{File.basename(file)}/"
mount -uw /
Then we need to load a couple of required system modules. DirectoryServices is only required if you want networking support.
launchctl load /System/Library/LaunchDaemons/com.apple.notifyd.plist
launchctl load /System/Library/LaunchDaemons/com.apple.kextd.plist
launchctl load /System/Library/LaunchDaemons/com.apple.diskarbitrationd.plist
launchctl start com.apple.diskarbitrationd
launchctl load /System/Library/LaunchDaemon/com.apple.DirectoryServices.plist
Etc.passwd { |d| users[d.name] = d.uid if d.uid > 500 }