Skip to content

Instantly share code, notes, and snippets.

View zentourist's full-sized avatar

Dan Wanek zentourist

View GitHub Profile
# This is kind of counter-intuitive because at first thought one wouldn't really want to have multiple
# instances of a Singleton class. There is an instance however where I needed exactly this. When creating
# a SOAP service the Singleton pattern works nice because you can just call the Singleton#instance method to
# fetch the instance without having to manually pass the object around. The trouble comes when you want
# connections to multiple SOAP endpoints. This is a test solution that I came up with to mock create multiple
# instances of a Singleton class.
require 'singleton'
class TestA
@zentourist
zentourist / enumerate_public_folders.rb
Created November 18, 2010 19:59
How to export Public Folder data with Viewpoint
def enum_flds(node = nil, path = '')
root = ( node.nil? ? :publicfoldersroot : node.folder_id )
name = ( node.nil? ? '' : node.display_name )
GenericFolder.find_folders(root).each do |f|
enum_flds(f, "#{path}#{(path=='/' ? '' : '/')}#{name}")
end
puts "Folder: #{path}#{(path=='/' ? '' : '/')}#{name}"
end
enum_flds
@zentourist
zentourist / extended_props.rb
Created April 5, 2011 13:53
Examples of ExtendedProperty use in EWS
# Set some ExtendedProperties
tag = {:preformatted => []}
tag[:preformatted] << {:set_item_field => [
{:extended_field_uRI=>{:distinguished_property_set_id=>"PublicStrings", :property_name=>"viewpoint_tags", :property_type=>"StringArray"}},
{:message => [
{:extended_property => [
{:extended_field_uRI=>{:distinguished_property_set_id=>"PublicStrings", :property_name=>"viewpoint_tags", :property_type=>"StringArray"}},
{:values => [ {:value => {:text => 'test_a'} }, {:value => {:text => 'test_b'}}]}
]}
@zentourist
zentourist / multi_inst_singleton.rb
Created May 31, 2011 19:06
A gross hack of a multi-instance singleton
# I know this doesn't make much sense, but I used it as an example of working with Handsoap which is a singleton,
# but I had the need for multiple, simultaneous connections.
class Master
@@instances = {}
def self.new(host)
return @@instances[host] if @@instances.has_key?(host)
super
@zentourist
zentourist / adctl.sh
Created July 25, 2011 16:43
Script to add Mac OS hosts to Active Directory
#!/usr/bin/env bash
# Dan Wanek
# Mon Jul 25 11:43:54 CDT 2011
#
# There is a good document from Apple on how to set up Active Directory for Mac that can be found
# at http://www.seminars.apple.com/contactme/pdf/L334436B_ActiveDirect_WP.pdf
# Default settings
COMPUTER_NAME=`hostname -s | tr "[:lower:]" "[:upper:]"`
RENAME_COMPUTER=false
@zentourist
zentourist / demo_ostruct.rb
Created July 28, 2011 19:00
Using OpenStruct
require 'ostruct'
require 'yaml'
class Configurator < OpenStruct
$rc_file = "#{ENV['HOME']}/.rubyconfs/myconf.yaml"
def self.read_config
if(File.exists?($rc_file))
YAML.load(File.read($rc_file))
@zentourist
zentourist / delegate_access.rb
Created August 18, 2011 02:41
Getting delegate access to another users Exchange folder in Viewpoint
require 'json'
require 'viewpoint'
include Viewpoint::EWS
puts "Usage: cal_items.rb <email>" if ARGV.length == 0
email = ARGV[0]
cfile="creds_test.json"
creds = JSON.load(File.open(cfile,'r'))
Viewpoint::EWS::EWS.endpoint = creds['endpoint']
Viewpoint::EWS::EWS.set_auth(creds['user'],creds['pass'])
cal = GenericFolder.get_folder(:calendar, email)
@zentourist
zentourist / ldap_user_rpt.ps1
Created August 25, 2011 03:55
Create an Excel report of Active Directory Users in an OU
# A script to fetch AD Users and put them into a spreadsheet
# Dan Wanek <[email protected]>
# 08/24/2011 22:36:00
param(
[int]$limit = 20,
[string]$ou = "",
[string]$outFile = $(Get-Location).Path + "\LDAP_USER_RPT.xls",
[switch]$verbose,
[switch]$usage
@zentourist
zentourist / nokogiri_build.rb
Created January 13, 2012 13:37
Nokogiri parameterized Builder
require 'nokogiri'
def mkxml(b, nm, bhash)
b.send(nm.to_s) {
bhash.each_pair do |k, v|
if(v.is_a?(Hash))
mkxml(b, k, v)
elsif(v.is_a?(Array))
b.send(k, v.shift, v[0].keys.first => v[0].values.first)
else
@zentourist
zentourist / file_lastline.rb
Created February 14, 2012 01:25
Return the last line of a File in a O(n) time
class File
def last_line
ind = 1
loop do
offset = (ind * -80)
if(offset >= size)
seek(0, IO::SEEK_SET)
line = read
line.chomp!
return line.split(/\n/, -1).last