<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Stayefeh's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 02:11:01 GMT</pubDate>
    <description>DZone Snippets: Stayefeh's Code Snippets</description>
    <item>
      <title>Using Google's API to Access Picasa Albums</title>
      <link>http://snippets.dzone.com/posts/show/5672</link>
      <description>Google provides its API in multiple languages. Here is an example that shows how to access a picasa album.&lt;br /&gt;&lt;br /&gt;Before you start, you need to download Google's API for .NET. Then copy the files to you project (in the project explorer) in Visual Studio and in the references in the project explorer. Now you can make use of the namespaces:&lt;br /&gt;&lt;br /&gt;using Google.GData.Client;&lt;br /&gt;using Google.GData.Photos;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;namespace GetPicasaFeed&lt;br /&gt;{&lt;br /&gt;    public partial class Form1 : Form&lt;br /&gt;    {&lt;br /&gt;        public Form1()&lt;br /&gt;        {&lt;br /&gt;            InitializeComponent();&lt;br /&gt;            this.getAtomFeed();&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        private void getAtomFeed()&lt;br /&gt;        {&lt;br /&gt;&lt;br /&gt;            // Album query and picasa query are specialized atomfeed classes&lt;br /&gt;            AlbumQuery aQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("saschatayefeh"));&lt;br /&gt;            PicasaService pService = new PicasaService("PicasaDemo");&lt;br /&gt;            AtomFeed kResultFeed = pService.Query(aQuery);&lt;br /&gt;&lt;br /&gt;            foreach (AtomEntry entry in kResultFeed.Entries)&lt;br /&gt;            {&lt;br /&gt;                this.textBox1.AppendText(entry.Title.Text + "\r\n");&lt;br /&gt;                foreach (AtomLink eLink in entry.Links)&lt;br /&gt;                {&lt;br /&gt;                    this.textBox1.AppendText("  " + eLink.HRef.ToString() + "\r\n"); ;&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            return;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt; &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jun 2008 08:36:37 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5672</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Accessing a web service </title>
      <link>http://snippets.dzone.com/posts/show/5671</link>
      <description>1. In Visual Studio, add a web reference in the project explorer.&lt;br /&gt;&lt;br /&gt;2. Create an class describing an object that represents the web service.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;    public class CurrentWeather&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;        #region attributes&lt;br /&gt;&lt;br /&gt;        private String location;&lt;br /&gt;        private String time;&lt;br /&gt;        private String wind;&lt;br /&gt;        private String visibility;&lt;br /&gt;        private String temperature;&lt;br /&gt;        private String dewPoint;&lt;br /&gt;        private String relativeHumidity;&lt;br /&gt;        private String pressure;&lt;br /&gt;        private String status;&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        #region properties&lt;br /&gt;&lt;br /&gt;        public String Location { get { return this.location; } set { this.location = value; } }&lt;br /&gt;        public String Time { get { return this.time; } set { this.time = value; } }&lt;br /&gt;        public String Wind { get { return this.wind; } set { this.wind = value; } }&lt;br /&gt;        public String Visibility { get { return this.visibility; } set { this.visibility = value; } }&lt;br /&gt;        public String Temperature { get { return this.temperature; } set { this.temperature = value; } }&lt;br /&gt;        public String DewPoint { get { return this.dewPoint; } set { this.dewPoint = value; } }&lt;br /&gt;        public String RelativeHumidity { get { return this.relativeHumidity; } set { this.relativeHumidity = value; } }&lt;br /&gt;        public String Pressure { get { return this.pressure; } set { this.pressure = value; } }&lt;br /&gt;        public String Status { get { return this.status; } set { this.status = value; } }&lt;br /&gt;&lt;br /&gt;        #endregion&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Use a method like this to call the service&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;        private void btRead_Click(object sender, EventArgs e)&lt;br /&gt;        {&lt;br /&gt;            net.webservice.www.MyWeather gw = new net.webservice.www.MyWeather ();&lt;br /&gt;            this.lblShowStatus.Text = "Accessing Service";&lt;br /&gt;            this.Refresh();&lt;br /&gt; &lt;br /&gt;            Objects.CurrentWeather cwo = new Objects.CurrentWeather();&lt;br /&gt;            System.Xml.Serialization.XmlSerializer xs =&lt;br /&gt;                new System.Xml.Serialization.XmlSerializer(typeof(Objects.CurrentWeather));&lt;br /&gt;&lt;br /&gt;            // Deserialize&lt;br /&gt;            try&lt;br /&gt;            {&lt;br /&gt;                System.IO.TextReader tr = new System.IO.StringReader(gw.GetWeather(this.tbCity.Text, this.tbCountry.Text));&lt;br /&gt;                cwo = (Objects.CurrentWeather)xs.Deserialize(tr);&lt;br /&gt;                this.lblShowStatus.Text = cwo.Status;&lt;br /&gt;                this.lbShowHumidity.Text = cwo.RelativeHumidity;&lt;br /&gt;                this.lbShowPressure.Text = cwo.Pressure;&lt;br /&gt;                this.lbShowWind.Text = cwo.Wind;&lt;br /&gt;                this.lbShowTemperature.Text = cwo.Temperature;&lt;br /&gt;            }&lt;br /&gt;            catch&lt;br /&gt;            {&lt;br /&gt;                this.lblShowStatus.Text = String.Empty;&lt;br /&gt;                this.lbShowHumidity.Text = String.Empty;&lt;br /&gt;                this.lbShowPressure.Text = String.Empty;&lt;br /&gt;                this.lbShowWind.Text = String.Empty;&lt;br /&gt;                this.lbShowTemperature.Text = String.Empty;&lt;br /&gt;                this.lblShowStatus.Text = "Error";&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 19 Jun 2008 08:23:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5671</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Pretty Print All Header and C++ files in a directory </title>
      <link>http://snippets.dzone.com/posts/show/4063</link>
      <description>&lt;code&gt;&lt;br /&gt;#!/bin/sh -&lt;br /&gt;&lt;br /&gt;echo 'Pretty Print Script v0.2 by s tayefeh (2004)'&lt;br /&gt;echo 'collects all .C .cc .cpp and .h from a ./.'&lt;br /&gt;echo 'and create a PRETTY_C.ps file with the C-sources'&lt;br /&gt;echo 'and a PRETTY_h.ps file with the header-sources'&lt;br /&gt;&lt;br /&gt;ls -lq *.C *.cc *.cpp \&lt;br /&gt;        | awk '{printf "%s ", $8}' \&lt;br /&gt;        &gt; clist.temp&lt;br /&gt;&lt;br /&gt;ls -lq *.h \&lt;br /&gt;        | awk '{printf "%s ", $8}' \&lt;br /&gt;        &gt; hlist.temp&lt;br /&gt;&lt;br /&gt;a2ps --prologue=color -Ec++ -o PRETTY_C.ps \&lt;br /&gt;`cat clist.temp` $1 $2 $3 $4&lt;br /&gt;&lt;br /&gt;a2ps --prologue=color -Ec++ -o PRETTY_h.ps \&lt;br /&gt;`cat hlist.temp` $1 $2 $3 $4&lt;br /&gt;&lt;br /&gt;rm hlist.temp clist.temp&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 24 May 2007 18:18:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4063</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Trivial AWT-only Event Handling</title>
      <link>http://snippets.dzone.com/posts/show/4062</link>
      <description>------------------------------------------------------------&lt;br /&gt;1. Main Class&lt;br /&gt;------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Main {&lt;br /&gt;&lt;br /&gt;        public static void main(final String[] args) {&lt;br /&gt;                MainFrameCommand cmd = new MainFrameCommand();&lt;br /&gt;                MainFrameGUI gui = new MainFrameGUI(cmd);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;------------------------------------------------------------&lt;br /&gt;2. MainFrameCommand  Class&lt;br /&gt;------------------------------------------------------------&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;class MainFrameCommand&lt;br /&gt;implements KeyListener, MouseMotionListener, WindowListener {&lt;br /&gt;&lt;br /&gt;        /* Key Listener */&lt;br /&gt;        public void keyPressed(KeyEvent event) {}&lt;br /&gt;        public void keyReleased(KeyEvent event) {}&lt;br /&gt;        public void keyTyped(KeyEvent event) {}&lt;br /&gt;&lt;br /&gt;        /* MouseMotion Listener */&lt;br /&gt;        public void mouseMoved(MouseEvent event) {}&lt;br /&gt;        public void mouseDragged(MouseEvent event) {}&lt;br /&gt;&lt;br /&gt;        /* WindowListener */&lt;br /&gt;        public void windowClosed(WindowEvent event) {}&lt;br /&gt;        public void windowOpened(WindowEvent event) {}&lt;br /&gt;        public void windowClosing(WindowEvent event) {}&lt;br /&gt;        public void windowActivated(WindowEvent event) {}&lt;br /&gt;        public void windowDeactivated(WindowEvent event) {}&lt;br /&gt;        public void windowIconified(WindowEvent event) {}&lt;br /&gt;        public void windowDeiconified(WindowEvent event) {}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;------------------------------------------------------------&lt;br /&gt;3. MainFrameGUI Class&lt;br /&gt;------------------------------------------------------------&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.awt.*;&lt;br /&gt;import java.awt.event.*;&lt;br /&gt;&lt;br /&gt;class MainFrameGUI extends Frame {&lt;br /&gt;                public MainFrameGUI(MainFrameCommand cmd) {&lt;br /&gt;                super("Window");&lt;br /&gt;                setSize(300, 300);&lt;br /&gt;                setVisible(true);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                addKeyListener(cmd);&lt;br /&gt;                addWindowListener(cmd);&lt;br /&gt;                addMouseMotionListener(cmd);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        public void paint(Graphics g) {}&lt;br /&gt;} &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 24 May 2007 17:43:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4062</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Blacklist String Validator Class</title>
      <link>http://snippets.dzone.com/posts/show/4047</link>
      <description>Check string for forbidden stuff. The constructur needs one single string argument, that contains the URI to the blacklist.txt file. This list contains one word per line of words that must not occur in the string to validate.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;   /*&lt;br /&gt;   CheckContent&lt;br /&gt;   (c) 2007 by S TAYEFEH&lt;br /&gt;&lt;br /&gt;   Check string for forbidden stuff.&lt;br /&gt;   The constructur needs one single string argument, &lt;br /&gt;   that contains the URI to the blacklist.txt file. &lt;br /&gt;   This list contains one word per line of words that &lt;br /&gt;   must not occur in the string to validate.&lt;br /&gt;&lt;br /&gt;   Example use:&lt;br /&gt;&lt;br /&gt;      require_once "CheckContent.php";&lt;br /&gt;      $val = new CheckContent("pbblacklist.txt");&lt;br /&gt;      if ($val-&gt;validate("blabla")) echo "ok";&lt;br /&gt;      else echo "failed";&lt;br /&gt;&lt;br /&gt;   */&lt;br /&gt;&lt;br /&gt;   class CheckContent&lt;br /&gt;   {&lt;br /&gt;      public $blacklistFN; // The textfile with the list of prohibited expressions&lt;br /&gt;      public $content="";  // The content to check - A single string&lt;br /&gt;      private $blacklistA=array();&lt;br /&gt;      private $isValid=TRUE;&lt;br /&gt;&lt;br /&gt;      // constructor&lt;br /&gt;      public function CheckContent($blacklist)&lt;br /&gt;      {&lt;br /&gt;	 $this-&gt;isValid=TRUE;&lt;br /&gt;	 $this-&gt;blacklistFN=$blacklist;&lt;br /&gt;	 $this-&gt;content="EMPTY";&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      // Main Method&lt;br /&gt;      public function validate($content)&lt;br /&gt;      {&lt;br /&gt;	 $this-&gt;content=$content;&lt;br /&gt;	 if(!$this-&gt;readFile()) return FALSE;&lt;br /&gt;&lt;br /&gt;	 foreach ($this-&gt;blacklistA as $a)&lt;br /&gt;	 {&lt;br /&gt;	    if(preg_match('/'.$a.'/i',$content)) $this-&gt;isValid=FALSE;&lt;br /&gt;	 }&lt;br /&gt;	 return $this-&gt;isValid;&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;      // Read File&lt;br /&gt;      private function readFile()&lt;br /&gt;      {&lt;br /&gt;	 $blacklistTemp=array();&lt;br /&gt;	 $blacklistS=FALSE;&lt;br /&gt;	 $blacklistS=file_get_contents($this-&gt;blacklistFN);&lt;br /&gt;	 if (!$blacklistS) &lt;br /&gt;	  {&lt;br /&gt;	     echo "*** ERROR from CheckContent:: - Could not read blacklist file: ".$this-&gt;blacklistFN;&lt;br /&gt;	     return FALSE;&lt;br /&gt;	  }&lt;br /&gt;	 $blacklistTemp=explode("\n",$blacklistS);&lt;br /&gt;	 // Clean array&lt;br /&gt;	 $this-&gt;blacklistA=array();&lt;br /&gt;	 // Only lines that contain letters or digits&lt;br /&gt;	 foreach ($blacklistTemp as $a) if( ereg("[a-zA-Z0-9]",$a) ) array_push($this-&gt;blacklistA,trim($a));&lt;br /&gt;	 sort($this-&gt;blacklistA); // Cosmetic ;-)&lt;br /&gt;	 return TRUE;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 21 May 2007 15:38:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4047</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Read File Linewise with Java</title>
      <link>http://snippets.dzone.com/posts/show/4045</link>
      <description>&lt;br /&gt;Here's the class&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class MyIO {&lt;br /&gt;	void printFile(String fileName) {&lt;br /&gt;		BufferedReader rd;&lt;br /&gt;		String line;&lt;br /&gt;&lt;br /&gt;		try {&lt;br /&gt;			rd = new BufferedReader(new FileReader(fileName));&lt;br /&gt;						&lt;br /&gt;			while ((line =  rd.readLine()  ) != null) {&lt;br /&gt;				System.out.println(line);&lt;br /&gt;			}&lt;br /&gt;			rd.close();&lt;br /&gt;		} catch (final IOException e) {&lt;br /&gt;			System.out.println("Error reading file");&lt;br /&gt;		}&lt;br /&gt;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All along with an example usage:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;	MyIO myIO = new MyIO();&lt;br /&gt;	myIO.printFile("filename.txt");&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 20 May 2007 13:03:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4045</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Using java.io.File object</title>
      <link>http://snippets.dzone.com/posts/show/4043</link>
      <description>Using java.io.File object&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;class Main {&lt;br /&gt;	static String filename = new String("/home/sascha/temp/changes.xml");	&lt;br /&gt;	&lt;br /&gt;	public static void main(String[] args) {&lt;br /&gt;		File fileObject;&lt;br /&gt;		System.out.println("Reading File: " + filename);&lt;br /&gt;&lt;br /&gt;		fileObject = new File(filename);&lt;br /&gt;		&lt;br /&gt;		System.out.println("Filename: " + fileObject.getName());&lt;br /&gt;		System.out.println("Length: " + (fileObject.length()) + "bytes");&lt;br /&gt;		System.out.println("Last modified timesptamp: " + fileObject.lastModified());&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 20 May 2007 10:24:14 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4043</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Create DLL with C# (C-sharp)</title>
      <link>http://snippets.dzone.com/posts/show/3861</link>
      <description>&lt;br /&gt;HowTo create a dynamically linked library (DLL) with C# (C-sharp) and &lt;br /&gt;Visual Studio 2005.&lt;br /&gt;&lt;br /&gt;HowTo create a dynamically linked library (DLL) with C# (C-sharp) and &lt;br /&gt;Visual Studio 2005.&lt;br /&gt;&lt;br /&gt;1. Creating the DLL:&lt;br /&gt;&lt;br /&gt;	a) Create a new project -&gt; C# Classlibrary.&lt;br /&gt;	&lt;br /&gt;	b) Create your class adding or modifying&lt;br /&gt;	   a class-file to the project and entering&lt;br /&gt;	   something like:&lt;br /&gt;	   &lt;code&gt;&lt;br /&gt;		using System;&lt;br /&gt;		using System.Collections.Generic;&lt;br /&gt;		using System.Text;&lt;br /&gt;&lt;br /&gt;		namespace MyClassLib&lt;br /&gt;		{&lt;br /&gt;		    public class ClassA&lt;br /&gt;		    {&lt;br /&gt;			public int PropA = 10;&lt;br /&gt;&lt;br /&gt;			public void Multiply()&lt;br /&gt;			{&lt;br /&gt;			    PropA *= 2;&lt;br /&gt;			}&lt;br /&gt;&lt;br /&gt;			public void Multiply(Int32 myFactor)&lt;br /&gt;			{&lt;br /&gt;			    PropA *= myFactor;&lt;br /&gt;			}&lt;br /&gt;&lt;br /&gt;		    }&lt;br /&gt;	  &lt;/code&gt;&lt;br /&gt;	   &lt;br /&gt;2. Test-bind the DLL&lt;br /&gt;	&lt;br /&gt;	a) Create another project WITHOUT closing or deleting the old project.&lt;br /&gt;	   (This is done by right-clicking on the Project-Explorer and &lt;br /&gt;	    choosing Add-&gt;New Project)&lt;br /&gt;&lt;br /&gt;	b) The new project needs to now about the DLL. The terminology is &lt;br /&gt;	   different from that of C++. Here, we talk about "references" instead&lt;br /&gt;	   of links. Thus, we have to add the DLL to the reference tree of the&lt;br /&gt;	   new project in the project-explorer. Rightclick on your&lt;br /&gt;	   new project-&gt;add reference-&gt;choose tab:Project and add.&lt;br /&gt;	   &lt;br /&gt;	c) To make life easier, use the namespace of your dll. Your&lt;br /&gt;	   main code could look something like this:&lt;br /&gt;	   &lt;br /&gt;	  &lt;code&gt;	   &lt;br /&gt;	   using System;&lt;br /&gt;	   using System.Collections.Generic;&lt;br /&gt;	   using System.Text;&lt;br /&gt;	   using MyClassLib;&lt;br /&gt;	   &lt;br /&gt;	   namespace ConsoleApplication1&lt;br /&gt;	   {&lt;br /&gt;	       class Program&lt;br /&gt;	       {&lt;br /&gt;	           static void Main(string[] args)&lt;br /&gt;	           {&lt;br /&gt;	               ClassA obj = new ClassA();&lt;br /&gt;	               obj.PropA = 9;&lt;br /&gt;	               obj.Multiply(9);&lt;br /&gt;	               Console.WriteLine(obj.PropA);&lt;br /&gt;	               Console.ReadLine();&lt;br /&gt;	           }&lt;br /&gt;	       }&lt;br /&gt;	   }&lt;br /&gt;	   &lt;/code&gt;&lt;br /&gt;	   &lt;br /&gt;Remember: The force is with you!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 23 Apr 2007 17:47:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3861</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>Most elementary Win-API "Hello, 'ere I am' code</title>
      <link>http://snippets.dzone.com/posts/show/3786</link>
      <description>This does nothing but opening a window for 5 seconds. No MFC, no C#, no resources, no whatsoever...&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include&lt;windows.h&gt; &lt;br /&gt;#include&lt;tchar.h&gt;&lt;br /&gt;&lt;br /&gt;HWND NewWindow(&lt;br /&gt;			   LPCTSTR str_Title,&lt;br /&gt;			   int int_XPos, &lt;br /&gt;			   int int_YPos, &lt;br /&gt;			   int int_Width, &lt;br /&gt;			   int int_Height);&lt;br /&gt;&lt;br /&gt;LRESULT CALLBACK OurWindowProcedure(&lt;br /&gt;									HWND han_Wind,&lt;br /&gt;									UINT uint_Message,&lt;br /&gt;									WPARAM parameter1,&lt;br /&gt;									LPARAM parameter2);&lt;br /&gt;&lt;br /&gt;int WINAPI WinMain(&lt;br /&gt;				   HINSTANCE hInstance,&lt;br /&gt;				   HINSTANCE hPreviousInstance,&lt;br /&gt;				   LPSTR lpcmdline,&lt;br /&gt;				   int nCmdShow&lt;br /&gt;				   )&lt;br /&gt;	{&lt;br /&gt;	HWND han_Window = NewWindow(_T("DirectX C++ Tutorial"),100,100,500,500);&lt;br /&gt;	Sleep(5000);&lt;br /&gt;	DestroyWindow(han_Window);&lt;br /&gt;	return 0;&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;HWND NewWindow(&lt;br /&gt;			   LPCTSTR str_Title,&lt;br /&gt;			   int int_XPos, &lt;br /&gt;			   int int_YPos, &lt;br /&gt;			   int int_Width, &lt;br /&gt;			   int int_Height)&lt;br /&gt;	{&lt;br /&gt;&lt;br /&gt;	WNDCLASSEX wnd_Structure;&lt;br /&gt;&lt;br /&gt;	wnd_Structure.cbSize = sizeof(WNDCLASSEX);&lt;br /&gt;	wnd_Structure.style = CS_HREDRAW | CS_VREDRAW;&lt;br /&gt;	wnd_Structure.lpfnWndProc = OurWindowProcedure;&lt;br /&gt;	wnd_Structure.cbClsExtra = 0;&lt;br /&gt;	wnd_Structure.cbWndExtra = 0;&lt;br /&gt;	wnd_Structure.hInstance = GetModuleHandle(NULL);&lt;br /&gt;	wnd_Structure.hIcon = NULL;&lt;br /&gt;	wnd_Structure.hCursor = NULL;&lt;br /&gt;	wnd_Structure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);&lt;br /&gt;	wnd_Structure.lpszMenuName = NULL;&lt;br /&gt;	wnd_Structure.lpszClassName = _T("WindowClassName");&lt;br /&gt;	wnd_Structure.hIconSm = LoadIcon(NULL,IDI_APPLICATION);&lt;br /&gt;&lt;br /&gt;	RegisterClassEx(&amp;wnd_Structure);&lt;br /&gt;&lt;br /&gt;	return CreateWindowEx(&lt;br /&gt;		WS_EX_CONTROLPARENT, &lt;br /&gt;		_T("WindowClassName"), &lt;br /&gt;		str_Title, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE,&lt;br /&gt;		int_XPos, &lt;br /&gt;		int_YPos, &lt;br /&gt;		int_Width, &lt;br /&gt;		int_Height, &lt;br /&gt;		NULL, &lt;br /&gt;		NULL, &lt;br /&gt;		GetModuleHandle(NULL),&lt;br /&gt;		NULL);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;LRESULT CALLBACK OurWindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)&lt;br /&gt;	{&lt;br /&gt;	return DefWindowProc(han_Wind,uint_Message,parameter1,parameter2);&lt;br /&gt;	}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 07 Apr 2007 18:11:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3786</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
    <item>
      <title>logmem.sh</title>
      <link>http://snippets.dzone.com/posts/show/3709</link>
      <description>&lt;br /&gt;continuously prints active memory from /proc/meminfo&lt;br /&gt;if fileentries exceed MAXENTRIES, then file is bzipped&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh&lt;br /&gt;# logmem.sh&lt;br /&gt;# 2007 by Sascha Tayefeh&lt;br /&gt;# continuously prints active memory from /proc/meminfo&lt;br /&gt;# if fileentries exceed MAXENTRIES, then file is bzipped&lt;br /&gt;# created for SUSE 10.2 &lt;br /&gt;# some adaptions may be needed for use with other linuxes&lt;br /&gt;#&lt;br /&gt;# usage (OPTIONS ORDER IS CRUTIAL!!!):&lt;br /&gt;# nohup /usr/bin/nice -n 19 logmem.sh [logfile.log] [maximum entries per logfile ] [logging interval in seconds]  &amp;&lt;br /&gt;#&lt;br /&gt;# example:&lt;br /&gt;# nohup /usr/bin/nice -n 19 logmem.sh mem.log 1747626 10  &amp;&lt;br /&gt;# nohup /usr/bin/nice -n 19 ~/src/sh/logmem.sh /tmp/mem.log 1747626 1 &gt;&amp; /tmp/logmem.sh.log &amp;&lt;br /&gt;# &lt;br /&gt;# to merge archived files do something like this:&lt;br /&gt;#&lt;br /&gt;# bunzip2 *.bz2&lt;br /&gt;# rm -f mem.merged.log &lt;br /&gt;# find . -name "mem*" -exec cat {} &gt;&gt; mem.merged.log \;&lt;br /&gt;#&lt;br /&gt;# to CUT by TIME:&lt;br /&gt;# cut -c9-29 mem.log&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Maximum number of entries per logfile&lt;br /&gt;# When exeeded, file will be archived &lt;br /&gt;&lt;br /&gt;pathToBzip="/usr/bin/bzip2"&lt;br /&gt;&lt;br /&gt;currentdir=`pwd`&lt;br /&gt;unamestring=`uname -a`&lt;br /&gt;hostname=$HOST&lt;br /&gt;pid=`ps -d | grep logmem | awk '{print $1}'`&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;echo "********************"&lt;br /&gt;echo logmem.sh 2007 by ST&lt;br /&gt;echo "********************"&lt;br /&gt;echo "unamestring: $unamestring"&lt;br /&gt;echo "host: $hostname"&lt;br /&gt;echo "user: $USER"&lt;br /&gt;echo "date: `date`"&lt;br /&gt;echo "logmem.sh PID: $pid"&lt;br /&gt;&lt;br /&gt;if [ $# -lt 3 ];&lt;br /&gt;then&lt;br /&gt;   echo&lt;br /&gt;   echo "******** ERROR: Too few arguments ********"&lt;br /&gt;   echo "******** I need to have EXACTLY 3 arguments !!! ***********"&lt;br /&gt;   echo&lt;br /&gt;   echo  "usage (OPTIONS ORDER IS CRUTIAL!!!):"&lt;br /&gt;   echo  "nohup /usr/bin/nice -n 19 logmem.sh [logfile.log] [maximum entries per logfile ] [logging interval in seconds]  &amp;"&lt;br /&gt;   echo &lt;br /&gt;   echo  "example:"&lt;br /&gt;   echo  "nohup /usr/bin/nice -n 19 logmem.sh mem.log 1747626 10  &amp;"&lt;br /&gt;   echo 'nohup /usr/bin/nice -n 19 ~/src/sh/logmem.sh /tmp/mem.log 1747626 1 &gt;&amp; /tmp/logmem.sh.log &amp;'&lt;br /&gt;&lt;br /&gt;   echo &lt;br /&gt;   exit&lt;br /&gt;else&lt;br /&gt;   let interval=$3&lt;br /&gt;   let MAXENTRIES=$2&lt;br /&gt;   logfile=$1&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;rm -f $logfile&lt;br /&gt;echo "logfile: $logfile"&lt;br /&gt;echo "loginterval: $interval"&lt;br /&gt;echo "syntax of logfile: [timestamp] [active mem] [active swap]"&lt;br /&gt;echo&lt;br /&gt;echo "to merge archived files do something like this:"&lt;br /&gt;echo &lt;br /&gt;echo " bunzip2 *.bz2"&lt;br /&gt;echo " rm -f mem.merged.log "&lt;br /&gt;echo " find . -name 'mem*' -exec cat {} &gt;&gt; mem.merged.log \;"&lt;br /&gt;echo &lt;br /&gt;echo "logging started until aborted by KILL or something..."&lt;br /&gt;echo &lt;br /&gt;&lt;br /&gt;let count=0&lt;br /&gt;&lt;br /&gt;# enter endless loop&lt;br /&gt;while [ 0 ];&lt;br /&gt;do&lt;br /&gt;   # get properties&lt;br /&gt;   let mem=`grep "Active" /proc/meminfo | awk '{print $2}'`&lt;br /&gt;   let swapTot=`grep "SwapTotal" /proc/meminfo | awk '{print $2}'`&lt;br /&gt;   let swapFree=`grep "SwapFree" /proc/meminfo | awk '{print $2}'`&lt;br /&gt;   let swapUsed=$swapTot-$swapFree&lt;br /&gt;   datestr=`date +'%Y%m%d %H%M%S'`&lt;br /&gt;&lt;br /&gt;   # log top file&lt;br /&gt;   echo "$datestr $mem $swapUsed " &gt;&gt; $logfile&lt;br /&gt;&lt;br /&gt;   # Achive file?&lt;br /&gt;   if [ $count -ge $MAXENTRIES ];&lt;br /&gt;   then&lt;br /&gt;      let count=0&lt;br /&gt;      $pathToBzip  -f -q -9 $logfile&lt;br /&gt;      mv "$logfile.bz2" "$logfile.$datestr.bz2"&lt;br /&gt;   fi&lt;br /&gt;&lt;br /&gt;   # fall asleep&lt;br /&gt;   sleep $interval&lt;br /&gt;&lt;br /&gt;   let count=$count+1&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 20 Mar 2007 16:27:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3709</guid>
      <author>stayefeh (Sascha Tayefeh)</author>
    </item>
  </channel>
</rss>
