Skip to content

Instantly share code, notes, and snippets.

View zenchild's full-sized avatar

Dan Wanek zenchild

View GitHub Profile
@zenchild
zenchild / 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)
@zenchild
zenchild / 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))
@zenchild
zenchild / 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
@zenchild
zenchild / 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
@zenchild
zenchild / 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'}}]}
]}
@zenchild
zenchild / 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
# 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
require 'openssl'
require 'yaml'
class Encryptor
def initialize(key_pass, key_size = 2048, key_name = 'rsakey.sec', cipher = OpenSSL::Cipher.new('aes-256-cbc'))
@key_size = key_size
@cipher = cipher
@key_name = key_name
require 'openssl'
class Encryptor
def initialize(key_pass, key_size = 1024, key_name = 'rsakey.sec', cipher = OpenSSL::Cipher.new('aes-256-cbc'))
@key_size = key_size
@cipher = cipher
@key_name = key_name
if( File.exists?(@key_name) )
// This is a convenience method that exists to determine if the window should be closed or not.
// There could be a lot more logic here, but for now we are just closing any window whose
// location property is equal to "chrome://global/content/commonDialog.xul", which is what the
// alert boxes that I have tested use.
alertClose: function (subject) {
if(subject.location == "chrome://global/content/commonDialog.xul") {
window.setTimeout(function() { subject.close(); }, 1000);
}
}