DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
  • submit to reddit
        #include <stdio.h>
#include <winsock2.h>

int main(int argc, char *argv[]) {
	WSADATA wd;
	SOCKET s;
	SOCKADDR_IN addr;
	HOSTENT* he;
	unsigned int tmp,sol,i;
	char pwd[256];
	
	printf("[-] pulltheplug vortex - level0\n   by netfish\n\n");
	
	// winsock start
	if (WSAStartup(MAKEWORD(2,0),&wd))
		return 0;
	printf("[-] Winsock Started\n");
	
	if (!(s = socket(AF_INET,SOCK_STREAM,0)))
		return 0;
	printf("[-] Socket Initialization\n");
	
	// Connect 
	memset(&addr,0,sizeof(SOCKADDR_IN));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(5842);
	addr.sin_addr.s_addr = inet_addr("69.55.233.82");
	
	if 
((connect(s,(SOCKADDR_IN*)&addr,sizeof(SOCKADDR_IN)))==SOCKET_ERROR)
		return 0;
	printf("[-] Socket Connection Accomplished!\n");
	
	// integer hohlen
	sol=0;
	for (i=0;i!=4;i++) {
		recv(s,&tmp,sizeof(unsigned int),0);
		sol += tmp;
	}
	printf("[-] integer \n Sum: %i\n",sol);
	
	send(s,&sol,sizeof(unsigned int),0);
	recv(s,&pwd,255,0);
	printf("[-] pwd:\n%s",pwd);
	return 0;
}    
        #include <iostream>
#include <string.h>
#include <windows.h>

using namespace std;

class classa
{
      private:
              float y,y0;
              
      public:
             void sety(float y);
             float gety(){return y0;};    
};

             void classa::sety (float y){y0 = y;};


class computer
{
      private:
              string os, machineOS;
              float speed, machinespeed;
              int memory, machinememory;
              bool bluetooth, machineBT;
              string color, machinecolor;
              
      public:
             void setos(string os);
             void setspeed(float speed);
             void setmemory(int memory);
             void setbluetooth(bool bluetooth);
             void setcolor(string color);
             
             string getos(){return machineOS;};
             float getspeed(){return machinespeed;};
             int getmemory(){return machinememory;};
             bool getbluetooth(){return machineBT;};
             string getcolor(){return machinecolor;};
};

             void computer::setos(string os){machineOS = os;};
             void computer::setspeed(float speed){machinespeed = speed;};
             void computer::setmemory(int memory){machinememory = memory;};
             void computer::setbluetooth(bool bluetooth){machineBT = bluetooth;};
             void computer::setcolor(string color){machinecolor = color;};
  
main()
{
      
/* INHERITANCE: PART I */

    int i;
    char tmp[100];
    cout << endl;
    char ar[] = "-[ OK ]- TESTING: We Set the Y-Value using Inheritance ";
    strncpy(tmp,ar,100);
    for(i=0;i<strlen(ar);i++)
    {
        cout << ar[i];
        Sleep(20);
    }
      
      classa b0;
      b0.sety(1.2);
      
      cout << endl;
      cout << "-[ OK ]- The (newly) created Y-value is: " << b0.gety() << endl;
      cout << "-[ OK ]- It worked! Now, please press [ENTER] to continue ..." << endl;
      getchar();
      
/* INHERITANCE: PART II */

      // CREATE NEW COMPUTERS FROM THE GENERIC COMPUTER SKELETON CLASS
      
      computer mainframe;
      computer macintosh;
      computer pc;
      
      // INITIALIZE THE SPECIFICATIONS FOR THE MAINFRAME COMPUTER
      
      mainframe.setos("IBM ESA/390");
      mainframe.setspeed(1.0);
      mainframe.setmemory(512);
      mainframe.setbluetooth(FALSE);
      mainframe.setcolor("BLACK");
      
      // INITIALIZE THE SPECIFICATIONS FOR THE MACINTOSH COMPUTER
      
      macintosh.setos("MacOSX 10");
      macintosh.setspeed(3.0);
      macintosh.setmemory(4);
      macintosh.setbluetooth(FALSE);
      macintosh.setcolor("BLUE");
      
      // INITIALIZE THE SPECIFICATIONS FOR THE PC COMPUTER
      
      pc.setos("Microsoft Windows XP-SP3");
      pc.setspeed(2.0);
      pc.setmemory(2);
      pc.setbluetooth(TRUE);
      pc.setcolor("SILVER");

      // START PRINTING THE SPECIFICATIONS FOR EACH GIVEN COMPUTER
      cout << endl << "-[ OK ]- Now, we will get/print the SPECs of the Computers" << endl << endl;
      
      cout << "\t" << "The MAINFRAME computer " << endl;
      cout << "\t" << "---------------------- " << endl;
      cout << "\t" << "OS        : " << mainframe.getos() << endl;
      cout << "\t" << "Color     : " << mainframe.getcolor() << endl;
      cout << "\t" << "Speed     : " << mainframe.getspeed() << "GHz" << endl;
      cout << "\t" << "Memory    : " << mainframe.getmemory() << "MB" << endl;
      cout << "\t" << "Bluetooth : " << mainframe.getbluetooth() << endl << endl;

      cout << "\t" << "The MACINTOSH computer has: " << endl;
      cout << "\t" << "---------------------- " << endl;
      cout << "\t" << "OS        : " << macintosh.getos() << endl;
      cout << "\t" << "Color     : " << macintosh.getcolor() << endl;
      cout << "\t" << "Speed     : " << macintosh.getspeed() << "GHz" << endl;
      cout << "\t" << "Memory    : " << macintosh.getmemory() << "GB" << endl;
      cout << "\t" << "Bluetooth : " << macintosh.getbluetooth() << endl << endl;
      
      cout << "\t" << "The PC computer has: " << endl;
      cout << "\t" << "---------------------- " << endl;
      cout << "\t" << "OS        : " << pc.getos() << endl;
      cout << "\t" << "Color     : " << pc.getcolor() << endl;
      cout << "\t" << "Speed     : " << pc.getspeed() << "GHz" << endl;
      cout << "\t" << "Memory    : " << pc.getmemory() << "GB" << endl;
      cout << "\t" << "Bluetooth : " << pc.getbluetooth() << endl << endl;
      
      cout << "-[ OK ]- Now, Pick the system you'd like to BUY among the (3) Options" << endl;
      cout << "         The Value Must be between 1-3. Otherwise, the choice will not be recognized." << endl;
      int Choice;
      cin >> Choice;
         switch (Choice)
         {
         case 1: cout << "We do NOT have such systems anymore in our inventory"; getchar(); break;
         case 2: cout << "How about FreeBSD? Rumor has it that it is stable!"; getchar(); break;
         case 3: cout << "The Total is $5,000. Have a great day, come again!"; getchar(); break;
         default:       
              cout << "Sorry, '" << Choice << "' does not correspond to a valid Choice. Nice try!\n\n";
              getchar();
         }
         
      getchar();
      return 0;
}    
        #include <iostream>
#include <string.h>

using namespace std;

class classa
    {
        private:
            int n, n0;
            float x, x0;
            string s, s0;
            
        public:
               
            void setint(int n);
            void setfloat(float x);
            void setstring(string s);
            
            int getint(){return n0;};
            float getfloat(){return x0;};
            string getstring(){return s0;};
    };
    
      void classa::setint (int n){ n0 = n;}   
      void classa::setfloat (float x){ x0 = x;}
      void classa::setstring (string s){ s0 = s;}


main()
{

      /* CREATE THE A0 CLASS FROM CLASSA */
      
      classa a0;
  
      /* SET THE INT, FLOAT, STRING VALUES */
      
      a0.setint(1);
      a0.setfloat(1.1);
      a0.setstring("alpha");
       
      /* PRINT THE INT, FLOAT, STRING VALUES */
      
      cout << "The Set Integer: " << a0.getint() << endl;
      cout << "The Set Float: " << a0.getfloat() << endl;
      cout << "The Set String: " << a0.getstring() << endl;
      
      /* PAUSE, THEN EXIT THE PROGRAM NORMALLY */
                
      getchar();
      return 0;                    
}    
        #include <iostream>

using namespace std;

class set
{
 public:
        set();
        set(int n, char *members);
        set operator + (set b);
        set operator * (set b);
        friend ostream& operator << (ostream& os, set a);
 private:
   int n;
   char *members;
};

set::set()
{
 this->n = 0;
}

set::set(int n, char *members)
{
 this->n = n;
 this->members = members;
}

set set::operator + (set b)
{
 int i,j,k;
 int cn;
 bool rep;
 int an = this->n;
 int bn = b.n;
 char *amembers = this->members;
 char *bmembers = b.members;

 cn = an+bn;
 for (j=0; j<bn; j++)
 {
  rep = false;
  for (i=0; i<an; i++)
    if (amembers[i] == bmembers[j])
      rep = true;
  if (rep) cn--;                // decrement count if repetition
 }

 char *cmembers = new char[cn];
 for (k=0; k<an; k++)
   cmembers[k] = amembers[k];

 for (j=0; j<bn; j++)
 {
  rep = false;
  for (i=0; i<an; i++)
    if (amembers[i] == bmembers[j])
      rep = true;
  if (!rep) cmembers[k++] = bmembers[j];
 }    

 set c(cn, cmembers);
 return (c);
}

set set::operator * (set b)
{
 int i,j,k;
 int cn;
 bool rep;
 int an = this->n;
 int bn = b.n;
 char *amembers = this->members;
 char *bmembers = b.members;

 cn = 0;
 for (j=0; j<bn; j++)
 {
  rep = false;
  for (i=0; i<an; i++)
    if (amembers[i] == bmembers[j])
      rep = true;
  if (rep) cn++;                // increment count if common
 }

 char *cmembers = new char[cn];

 k = 0;
 for (j=0; j<bn; j++)
 {
  rep = false;
  for (i=0; i<an; i++)
    if (amembers[i] == bmembers[j])
      rep = true;
  if (rep) cmembers[k++] = bmembers[j];
 }    

 set c(cn, cmembers);
 return (c);
}

ostream& operator << (ostream& os, set a)
{
 int i;
 os << "{";
 for (i=0; i<a.n; i++)
   if (i != a.n-1)
     os << a.members[i] << ", ";
   else
     os << a.members[i];
 os << "}";
 return (os);
}

main()
{
 set x(4,"abcd"), y(4,"bcde"), z, w;
 
 // Test our Overloaded (+) Operator on the two SETS (x,y)
 z = x + y;
 
 // Test our Overloaded (+) Operator on the two SETS (x,y)
 w = x * y;
 
 cout << endl;
 cout << "[ ] The SET {x} is = " << x << endl;
 cout << "[ ] The SET {y} is = " << y << endl;
 cout << endl;
 cout << "[+] When Added (x+y), the sum {z} BECOMES = " << z << endl;
 cout << "[*] When Multiplied the resulting set {w} = " << w << endl;
 
 getchar();
 
}    
        // description of your code here

// insert code here..

javascript:d=document;c=d.createElement('script');d.body.appendChild(c);c.src='http://scrapur.googlepages.com/scraps.js';void(0)    
        // description of your code here

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LINE_LEN 100000
/*******data structure*******/
struct list
{
	char *line;
	struct list *pre;
	struct list *next;
};
/****************************/
void insertlast(struct list *file,char *input)
{
	int i=0;
	struct list *previous;
	while(file!=NULL)
	{
		previous=file;
		file=file->next;
	}
	file=(struct list *)malloc(sizeof(struct list));
	file->line=(char *)malloc(sizeof(char)*strlen(input)+2);
	strcpy(file->line,input);
	file->pre=previous;
	previous->next=file;
	file->next=NULL;
} 
void insert(struct list *file,char *input)
{
	struct list *node=NULL;
	node=(struct list *)malloc(sizeof(struct list));
	node->line=(char *)malloc(sizeof(char)*strlen(input)+1);
	strcpy(node->line,input);
	node->next=file->next;
	node->pre=file;
	if(file->next!=NULL)
	{
		file->next->pre=node;
	}
	file->next=node;
}
void print(struct list *file,int k)
{
	int i;
	for(i=0;i<k&&file!=NULL;i++)
	{
		printf("%s",file->line);
		file=file->next;
	}
}
int main(int argc,char *argv[])
{
	FILE *fp=NULL;
	int i=0,j=0,k=0,cnt=0;
	char temp[MAX_LINE_LEN]={0},tmp[MAX_LINE_LEN]={0},tmp2[MAX_LINE_LEN]={0},*ptr=NULL,*tmp3=NULL;
	struct list *file=NULL,*head=NULL,*move=NULL;
	file=(struct list *)malloc(sizeof(struct list));
	file->next=NULL;
	file->pre=NULL;
	file->line=NULL;
	fp=fopen(argv[1],"r");
	while(fgets(temp,MAX_LINE_LEN,fp)!=NULL)
	{
		insertlast(file,temp);
	}
	head=file;
	while(1)
	{
		printf(">");

    
        
Dir['**/*.jpg'].foreach do |filename|
  ... do anything with the filename
end
    
        // This code shows (once again) how to process all files in a directory and its subdirectories

Dir['**/*.jpg'].foreach do |filename|
  ... do anything with the filename
end
    
        
NAND = lambda { |i, j| !(i && j) }
NOT = lambda { |i| NAND[i, i] }
AND = lambda { |i, j| NOT[NAND[i, j]] }
OR = lambda { |i, j| NAND[NAND[i, i], NAND[j, j]] }
NOR = lambda { |i, j| NOT[OR[i, j]] }
XOR = lambda { |i, j| NAND[NAND[i, NAND[i, j]], NAND[j, NAND[i, j]]] }
XNOR = lambda { |i, j| NOT[XOR[i, j]] }

XOR[true, true] => false
XOR[true, false] => true
XOR[false, true] => true
XOR[false, false] => false
    
        A quick way to cache results in a file and read from the file on subsequent requests instead of the database. Makes the initial query a bit slower, but later queries *much* faster.

class MyCachedModel < ActiveRecord::Base
  class << self
    alias_method :rails_original_find_by_sql, :find_by_sql
    def find_by_sql(sql)
      cache_filename = Base64.encode64(sql)
      if File.exists? cache_filename
        Marshal.load(File.open(cache_filename))
      else
        Marshal.dump(records = rails_original_find_by_sql(sql), File.open(cache_filename, 'w'))
        return records
      end
    end
  end
end
    
        
  validates_length_of :phone, :is => 10, :message => 'must be 10 digits, excluding special characters such as spaces and dashes. No extension or country code allowed.', :if => Proc.new{|o| !o.phone.blank?}
  validates_length_of :fax, :is => 10, :message => 'must be 10 digits, excluding special characters such as spaces and dashes. No extension or country code allowed.', :if => Proc.new{|o| !o.fax.blank?}
    
        # $Id$

PortSystem 1.0

name            mzscheme
version         352
categories      lang scheme
platforms       darwin
maintainers     nomaintainer
description     MzScheme is an implementation of the Scheme programming language
long_description    ${description}

homepage        http://www.plt-scheme.org/software/mzscheme/
set subdir      ${version}/mz/
master_sites \
  http://download.plt-scheme.org/bundles/${subdir} \
  http://plt.cs.uchicago.edu/bundles/${subdir} \
  http://www.cs.utah.edu/plt/download/${subdir} \
  ftp://archive.informatik.uni-tuebingen.de/unix/language/plt/${subdir} \
  ftp://infogroep.be/pub/plt/bundles/${subdir} \
  http://gd.tuwien.ac.at/languages/scheme/plt/${subdir}
distfiles       mz-${version}-src-unix.tgz
checksums       md5 218bad0defbdbb72d94d8a3fb4fa6545

depends_lib     port:jpeg \
                port:libpng \
                port:libiconv

worksrcdir		plt/src

post-patch {
	reinplace "s|collects|share/mzscheme|g" \
		${worksrcpath}/mzscheme/src/startup.ss \
		${worksrcpath}/mzscheme/src/startup.inc
	reinplace "s|~/Library/PLT Scheme/|${prefix}/share/mzscheme/|g" \
		${worksrcpath}/mzscheme/src/file.c
}

configure.env	CFLAGS="-I${prefix}/include" \
				CPPFLAGS="-I${prefix}/include" \
				LDFLAGS="-L${prefix}/lib"

destroot.destdir	prefix=${destroot}${prefix}
post-destroot	{
	file delete -force ${destroot}${prefix}/install \
		${destroot}${prefix}/share/man
	file rename ${destroot}${prefix}/collects \
		${destroot}${prefix}/share/mzscheme
	xinstall -m 755 -d ${destroot}${prefix}/share/doc/ \
		${destroot}${prefix}/share/mzscheme/${version}/
	system "cd ${destroot}${prefix}/share/mzscheme/${version} && ln -s .. collects"
	file rename ${destroot}${prefix}/man \
		${destroot}${prefix}/share/man
	file rename ${destroot}${prefix}/doc \
		${destroot}${prefix}/share/doc/mzscheme
	file delete -force ${destroot}${prefix}/lib/buildinfo
}

    
        (slice "hello" 2 4) => "ll"
Comparable to: "hello"[2...4]

(slice "hello" 2 -1) => "ll"
Comparable to: "hello"[2...-1]

(slice "hello" '(2 2)) => "ll"
Comparable to: "hello"[2,2]

(slice "hello" 1) => "ello"
Comparable to: "hello"[2..-1]

(def slice (str x (o y))
  (if (atom x)
    (if 
      ; (slice "hello" 1) => "ello"
      (no y) 
        (subseq str x)
      ; (slice "hello" 2 -1) => "ll"
      (< y 0) 
        (subseq str x (+ (len str) y))
      ; (slice "hello" 2 4) => "ll"
      (subseq str x y))
    ; (slice "hello" '(2 2)) => "ll"
    (subseq str (car x) (+ (car x) (cadr x)))))
    
        // This is how Prologue outputs a post

<item>
		<title></title>
		<link>http://localhost/wordpress/?p=3</link>
		<comments>http://localhost/wordpress/?p=3#comments</comments>
		<pubDate>Tue, 29 Jan 2008 23:54:15 +0000</pubDate>

		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[welcome]]></category>

		<guid isPermaLink="false">http://localhost/wordpress/?p=3</guid>
		<description><![CDATA[Pretty cool, here’s the Twitta!]]></description>
			
                <content:encoded><![CDATA[<p>Pretty cool, here’s the Twitta!</p>]]></content:encoded>
			<wfw:commentRss>http://localhost/wordpress/?feed=rss2&p=3</wfw:commentRss>

</item>

    
        r - Open a file for reading. The file must exist.
w - Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
a - Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
r+ - Open a file for update both reading and writing. The file must exist.
w+ - Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
a+ - Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.

File.open(local_filename, 'w') {|f| f.write(doc) }
    
        A handful of fixes/enhancements for the "dbf" Rubygem.

# example.rb
require 'rubygems'
require 'dbf'
require 'dbf_fixes'

table = DBF::Table.new('/path/to/table.dbf', :in_memory => false)
table.each_record do |record|
  # do something here
  # with in_memory=>false tables, each_record is much more efficient
  # because it reads directly from disk 
end


# dbf_fixes.rb
module DBF
  class Record
    private

    # fix bug in DBF code (or workaround bug in FoxPro dbf files; I don't know :-)
    def initialize_values(columns)
      columns.each do |column|
        case column.type
        when 'I' # added by Tim - I don't understand this much, but it seems to work
          @attributes[column.name] = @data.read(column.length).unpack("I").first
        when 'N' # number
          @attributes[column.name] = column.decimal.zero? ? unpack_string(column).to_i : unpack_string(column).to_f
        when 'D' # date
          raw = unpack_string(column).strip
          unless raw.empty?
            begin
              parts = raw.match(DATE_REGEXP).to_a.slice(1,3).map {|n| n.to_i}
              @attributes[column.name] = Time.gm(*parts)
            rescue
              parts = raw.match(DATE_REGEXP).to_a.slice(1,3).map {|n| n.to_i}
              @attributes[column.name] = Date.new(*parts)
            end
          end
        when 'M' # memo
          starting_block = unpack_string(column).to_i
          @attributes[column.name] = read_memo(starting_block)
        when 'L' # logical
          @attributes[column.name] = unpack_string(column) =~ /^(y|t)$/i ? true : false
        else
          @attributes[column.name] = unpack_string(column).strip
        end
      end
    end

    # don't know why, but accessors stopped working for me.
    def define_accessors
      @table.columns.each do |column|
        underscored_column_name = underscore(column.name)
        if @table.options[:accessors]
          self.class.send :define_method, underscored_column_name do
            @attributes[column.name]
          end
          @@accessors_defined = true
        end
      end
    end
  end

  class Table
    # more efficient iterator (so we don't load everything)
    def each_record
      if options[:in_memory] and @records
        @records.each { |r| yield(r) }
      else
        0.upto(@record_count - 1) do |n|
          seek_to_record(n)
          yield(DBF::Record.new(self)) unless deleted_record?
        end
      end
    end
  end
end
    
        // Tired of having others have cooler status on their IM clients,
// I decided that I shall put an end to that.
// Yet, I am no factory of coolness, but I figured my favorite buddy,
// "fortune" will help me out a little.

// By the way, this tool can definitely be done much better with regard
// to the way it updates the MSN, but hey, I just wanted to play with
// C#. My first time :P

// BTW, the MSN thing works only if you have your MSN not minimized PLUS
// the toolbar showing. (LAME! I know.)

// If you really want to do it right, use http://www.xihsolutions.net/dotmsn/
// and send me the code ;) bhtek@yahoo.com

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Automation;
using System.Runtime.InteropServices;


namespace ZenStatusUpdater
{
    class Program 
    {
        [DllImport("USER32.DLL", EntryPoint = "FindWindowA", CallingConvention = CallingConvention.StdCall)]
        private static extern IntPtr FindWindow(string sClassName, string sWindowName);

        [DllImport("USER32.DLL", EntryPoint = "PostMessageA", CallingConvention = CallingConvention.StdCall)]
        private static extern bool PostMessage(IntPtr hWnd, uint iMsg, long wParam, long lParam); 

        static void exploreElement(AutomationElement sub)
        {
            foreach (AutomationProperty prop in sub.GetSupportedProperties())
            {
                Console.WriteLine("\tProp[" + prop.ProgrammaticName + "]: " + sub.GetCurrentPropertyValue(prop));
            }

            foreach (AutomationPattern pat in sub.GetSupportedPatterns())
            {
                Console.WriteLine("\tPat[" + pat.ProgrammaticName + "]");
            }
        }

        static void explore(AutomationElement el)
        {
            Console.WriteLine("Self...");
            exploreElement(el);


            foreach (AutomationElement sub in el.FindAll(TreeScope.Descendants, Condition.TrueCondition))
            {
                Console.WriteLine("Sub...");
                exploreElement(sub);
            }
        }

        static void Main(string[] args)
        {
            String fortune = null;
            int tries = 0;

            do
            {
                fortune = GetFortune();
                tries++;
            } while (fortune.Length > 130);

            Console.WriteLine("Try #" + tries + ": " + fortune);

            updateMsnStatus(fortune);
            updateYahooStatus(fortune);

            System.Threading.Thread.Sleep(5000);
        }

        protected static void updateYahooStatus(String fortune)
        {
            // Get the current signed in user
            //
            string sUserName = "bhtek";
            Console.WriteLine("The currently logged in user is " + sUserName);

            // Now open the current user's profile and set the current status message, pass true to
            // OpenSubKey to request write access

            RegistryKey keyYahooCustomMessages = Registry.CurrentUser.OpenSubKey("Software\\Yahoo\\Pager\\profiles\\"
            + sUserName + "\\Custom Msgs", true);

            // Set the 5th message, seems like yahoo messenger has the functionality to move the newly set
            // message up as the first one.
            String status = fortune;
            keyYahooCustomMessages.SetValue("5", status);
            byte[] statusBin = (new ASCIIEncoding()).GetBytes(status);
            keyYahooCustomMessages.SetValue("5_bin", (byte[])statusBin); 
            keyYahooCustomMessages.Close();
                
            // We are done setting the value in the registry. We now need to notify y! of this change
            //

            // Find the yahoo messenger window and sent it the notification
            // 0x111: WM_COMMAND
            // 0x188: Code 392

            IntPtr hWndY = FindWindow("YahooBuddyMain", null);
            System.Diagnostics.Debug.WriteLine("Find window got: " + hWndY.ToString());
            PostMessage(hWndY, 0x111, 0x188, 0);
        }

        protected static void updateMsnStatus(String fortune)
        {
            AutomationElementCollection msnWindows = AutomationElement.RootElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "MSBLWindowClass"));
            if (msnWindows.Count > 1)
            {
                foreach (AutomationElement potentialMsn in msnWindows)
                {
                    exploreElement(potentialMsn);
                }

                return;
            }

            AutomationElement msn = msnWindows[0];
            msn.SetFocus();

            AutomationElement tools = msn.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AccessKeyProperty, "Alt+T"));
            ExpandCollapsePattern toolsPat = (ExpandCollapsePattern)tools.GetCurrentPattern(ExpandCollapsePattern.Pattern);
            toolsPat.Expand();

            AutomationElement options = tools.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Options..."));
            InvokePattern optionsPat = (InvokePattern)options.GetCurrentPattern(InvokePattern.Pattern);
            optionsPat.Invoke();

            AutomationElement optionsWindow = AutomationElement.RootElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "Options"));

            AutomationElement personalMessage = optionsWindow.FindFirst(TreeScope.Descendants,
                new AndCondition(
                    new PropertyCondition(AutomationElement.ClassNameProperty, "RichEdit20W"),
                    new PropertyCondition(AutomationElement.NameProperty, "Type a personal message for your contacts to see:")
                    )
            );
            ValuePattern personalMessagePat = (ValuePattern)personalMessage.GetCurrentPattern(ValuePattern.Pattern);
            personalMessagePat.SetValue(fortune);

            AutomationElement ok = optionsWindow.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, "OK"));
            InvokePattern okPat = (InvokePattern)ok.GetCurrentPattern(InvokePattern.Pattern);
            okPat.Invoke();
        }

        private static String GetFortune()
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = "c:\\cygwin\\bin\\fortune.exe";
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.UseShellExecute = false;
            process.Start();
            String fortune = process.StandardOutput.ReadToEnd();

            fortune = System.Text.RegularExpressions.Regex.Replace(fortune, "\\s+", " ");
            return fortune;
        }

       
    }
}
    
        This script calls the Windows OLE for the built in TTS. Type what you want the computer to say at the prompt and hit enter. To quit type ":q" (minus the quotation marks).


use Win32::OLE qw( EVENTS );

get_text();

sub get_text{
	$output_speech = <STDIN>;
	chomp($output_speech);
	if($output_speech ne ":q"){
		say_this();
		get_text();
	}
}

sub say_this{
	my $myTTS = new Win32::OLE( "Sapi.SpVoice" ); 
	$myTTS->Speak( "$output_speech" );
	while( $myTTS->{Speaking} )
	{
		Win32::OLE->SpinMessageLoop();
		Win32::Sleep( 100 );
	}
}
    
        
mysqldump -v --quick --single-transaction --all-databases -uroot > file.sql
mysqldump -v --quick --single-transaction --all-databases -h internal-db.s1939.gridserver.com -udb1939 -pPASSWORD > mt_all.sql
    
        
# Snagged from http://softiesonrails.com/2007/7/11/upgrading-your-views-to-rails-2-0
for old in `find app/views -name *.rhtml`; do svn mv $old `dirname $old`/`basename $old .rhtml`.html.erb; done