

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cardboard Coder &#187; Code Snippets</title>
	<atom:link href="http://www.cardboardcoder.com/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cardboardcoder.com</link>
	<description>Sometimes it&#039;s all you need...</description>
	<lastBuildDate>Tue, 25 May 2010 07:15:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Show Email in IMAP Mailbox with PHP (Retrieve Email)</title>
		<link>http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/</link>
		<comments>http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 09:09:20 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[POP3]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=533</guid>
		<description><![CDATA[How difficult is it to open a IMAP mailbox in PHP and show folder names and email headers, well, no difficult at all.

Here is the code:

$mbox = imap_open(&#34;{imap.example.org:143}&#34;, &#34;username&#34;, &#34;password&#34;);

echo &#34;
&#60;h1&#62;Mailboxes&#60;/h1&#62;
\n&#34;;
$folders = imap_listmailbox($mbox, &#34;{imap.example.org:143}&#34;, &#34;*&#34;);

if ($folders == false) {
echo &#34;Call failed
\n&#34;;
} else {
foreach ($folders as $val) {
echo $val . &#34;
\n&#34;;
}
}

echo &#34;
&#60;h1&#62;Headers in INBOX&#60;/h1&#62;
\n&#34;;
$headers = imap_headers($mbox);

if [...]]]></description>
			<content:encoded><![CDATA[<p>How difficult is it to open a IMAP mailbox in PHP and show folder names and email headers, well, no difficult at all.</p>
<p><span id="more-533"></span></p>
<p>Here is the code:</p>
<pre class="brush: php">
$mbox = imap_open(&quot;{imap.example.org:143}&quot;, &quot;username&quot;, &quot;password&quot;);

echo &quot;
&lt;h1&gt;Mailboxes&lt;/h1&gt;
\n&quot;;
$folders = imap_listmailbox($mbox, &quot;{imap.example.org:143}&quot;, &quot;*&quot;);

if ($folders == false) {
echo &quot;Call failed
\n&quot;;
} else {
foreach ($folders as $val) {
echo $val . &quot;
\n&quot;;
}
}

echo &quot;
&lt;h1&gt;Headers in INBOX&lt;/h1&gt;
\n&quot;;
$headers = imap_headers($mbox);

if ($headers == false) {
echo &quot;Call failed
\n&quot;;
} else {
foreach ($headers as $val) {
echo $val . &quot;
\n&quot;;
}
}

imap_close($mbox);
?&gt;
</pre>
<p>Yep, that&#8217;s it. Pass it your username and password and the script will display your email, local or remote. You can also expand upon this code to show the body of the emails and more information.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;t=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29+-+http://b2l.me/nkwz9+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;title=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;title=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;title=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;t=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;title=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;title=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29&amp;summary=How%20difficult%20is%20it%20to%20open%20a%20IMAP%20mailbox%20in%20PHP%20and%20show%20folder%20names%20and%20email%20headers%2C%20well%2C%20no%20difficult%20at%20all.%0D%0A%0D%0A%0D%0A%0D%0AHere%20is%20the%20code%3A%0D%0A%5Bsource%20language%3D%22php%22%5D%0D%0A%24mbox%20%3D%20imap_open%28%22%7Bimap.example.org%3A143%7D%22%2C%20%22username%22%2C%20%22password%22%29%3B%0D%0A%0D%0Aecho%20%22%0D%0AMailboxes%0D%0A%5Cn%22%3B%0D%0A%24folders%20%3D%20imap_listmailbox%28%24mbox%2C&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;title=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/&amp;title=Show+Email+in+IMAP+Mailbox+with+PHP+%28Retrieve+Email%29&amp;body=How%20difficult%20is%20it%20to%20open%20a%20IMAP%20mailbox%20in%20PHP%20and%20show%20folder%20names%20and%20email%20headers%2C%20well%2C%20no%20difficult%20at%20all.%0D%0A%0D%0A%0D%0A%0D%0AHere%20is%20the%20code%3A%0D%0A%5Bsource%20language%3D%22php%22%5D%0D%0A%24mbox%20%3D%20imap_open%28%22%7Bimap.example.org%3A143%7D%22%2C%20%22username%22%2C%20%22password%22%29%3B%0D%0A%0D%0Aecho%20%22%0D%0AMailboxes%0D%0A%5Cn%22%3B%0D%0A%24folders%20%3D%20imap_listmailbox%28%24mbox%2C" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Show%20Email%20in%20IMAP%20Mailbox%20with%20PHP%20%28Retrieve%20Email%29%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22How%20difficult%20is%20it%20to%20open%20a%20IMAP%20mailbox%20in%20PHP%20and%20show%20folder%20names%20and%20email%20headers%2C%20well%2C%20no%20difficult%20at%20all.%0D%0A%0D%0A%0D%0A%0D%0AHere%20is%20the%20code%3A%0D%0A%5Bsource%20language%3D%22php%22%5D%0D%0A%24mbox%20%3D%20imap_open%28%22%7Bimap.example.org%3A143%7D%22%2C%20%22username%22%2C%20%22password%22%29%3B%0D%0A%0D%0Aecho%20%22%0D%0AMailboxes%0D%0A%5Cn%22%3B%0D%0A%24folders%20%3D%20imap_listmailbox%28%24mbox%2C%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2010/04/show-email-in-imap-mailbox-with-php-retrieve-email/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WOL in VB.net</title>
		<link>http://www.cardboardcoder.com/2010/03/wol-in-vb-net/</link>
		<comments>http://www.cardboardcoder.com/2010/03/wol-in-vb-net/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 08:46:00 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[VB.net]]></category>
		<category><![CDATA[Wake On LAN]]></category>
		<category><![CDATA[WOL]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=497</guid>
		<description><![CDATA[I have found a really handy VB.net class to do Wake On LAN.  The original website is here:
http://www.lucamauri.com/snippet/snip.aspx?id=6

The code in full is:


Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class clsWOL
Const lenHeader As Integer = 6
Const lenMAC As Integer = 6
Const repMAC As Integer = 16

Dim mEndPoint As IPEndPoint
Dim mMACAddress As Byte()
Dim mBytesSent As Integer = 0
Dim mPacketSent As [...]]]></description>
			<content:encoded><![CDATA[<p>I have found a really handy VB.net class to do Wake On LAN.  The original website is here:</p>
<p><a href="http://www.lucamauri.com/snippet/snip.aspx?id=6">http://www.lucamauri.com/snippet/snip.aspx?id=6</a></p>
<p><span id="more-497"></span></p>
<p>The code in full is:</p>
<pre class="brush: vb.net">

Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class clsWOL
Const lenHeader As Integer = 6
Const lenMAC As Integer = 6
Const repMAC As Integer = 16

Dim mEndPoint As IPEndPoint
Dim mMACAddress As Byte()
Dim mBytesSent As Integer = 0
Dim mPacketSent As String

&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; The IPEndPoint object that will act as a trasport for the packet.
&#039;&#039;&#039; It is automatically created by New statement, but you can modify it or read it.
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;value&gt;An IPEndPoint object&lt;/value&gt;
&#039;&#039;&#039; &lt;returns&gt;An IPEndPoint object&lt;/returns&gt;
&#039;&#039;&#039; &lt;remarks&gt;Normally there is no need to change this manually.&lt;/remarks&gt;
Public Property endPoint() As IPEndPoint
Get
Return mEndPoint
End Get
Set(ByVal value As IPEndPoint)
mEndPoint = value
End Set
End Property
&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; The target machine Network Interface Card MAC address.
&#039;&#039;&#039; It must be dash-separated, i.e. in the 11-22-33-44-55-66 form
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;value&gt;A string with dash-separated values&lt;/value&gt;
&#039;&#039;&#039; &lt;returns&gt;A string with dash-separated values&lt;/returns&gt;
&#039;&#039;&#039; &lt;remarks&gt;The standard (IEEE 802) separator for cotet are dash (-) and semicolon (:). I resolved to use dashes only in order to avoid any possible confusion and misunderstanding with upcoming IPv6 addressing space.&lt;/remarks&gt;
Public Property macAddress() As String
Get
Dim textMAC As New StringBuilder

For Each currByte As Byte In mMACAddress
textMAC.Append(&quot;-&quot;)
textMAC.Append(currByte.ToString(&quot;X2&quot;))
Next

Return textMAC.ToString.Substring(1)
End Get
Set(ByVal value As String)
Dim values As Byte()

For Each currByte As String In value.Split(&quot;-&quot;)
If values Is Nothing Then
ReDim values(0)
Else
ReDim Preserve values(values.GetUpperBound(0) + 1)
End If
values(values.GetUpperBound(0)) = Byte.Parse(currByte, Globalization.NumberStyles.HexNumber)
Next

mMACAddress = values
End Set
End Property
&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; Total bytes sent by WakeIt method. It is 0 until the method is called at least once for this class instance.
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;returns&gt;Integer value, total bytes trasmitted&lt;/returns&gt;
&#039;&#039;&#039; &lt;remarks&gt;&lt;/remarks&gt;
Public ReadOnly Property bytesSent() As Integer
Get
Return mBytesSent
End Get
End Property
&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; It represent the Magic Packet broadcasted.
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;returns&gt;String containing the text parsing of the Magic Packet&lt;/returns&gt;
&#039;&#039;&#039; &lt;remarks&gt;&lt;/remarks&gt;
Public ReadOnly Property packetSent() As String
Get
Return mPacketSent
End Get
End Property
&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; Creates a WOL Magic Packet, the datagram that will awake the target PC updon broadcast on the network.
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;param name=&quot;macAddress&quot;&gt;An array of byte representing the target machine Network Interface Card MAC address&lt;/param&gt;
&#039;&#039;&#039; &lt;returns&gt;An array of byte representing the Magic Packet&lt;/returns&gt;
&#039;&#039;&#039; &lt;remarks&gt;This method can be used indipendently from the rest of the class. If necessary it can create a Magic Packet just providing the MAC address.&lt;/remarks&gt;
Public Function magicPacket(ByVal macAddress As Byte()) As Byte()
Dim payloadData As Byte()
Dim packet As New StringBuilder

Try
ReDim payloadData(lenHeader + lenMAC * repMAC)

For i As Integer = 0 To lenHeader - 1
payloadData(i) = Byte.Parse(&quot;FF&quot;, Globalization.NumberStyles.HexNumber)
Next
For i As Integer = 0 To repMAC - 1
For j As Integer = 0 To lenMAC - 1
payloadData(lenHeader + i * lenMAC + j) = macAddress(j)
Next
Next

For Each currLoad As Byte In payloadData
packet.Append(&quot;-&quot;)
packet.Append(currLoad.ToString(&quot;X2&quot;))
Next

mPacketSent = packet.ToString.Substring(1)
Catch ex As Exception
mPacketSent = &quot;EXCEPTION: &quot; &amp;amp; ex.ToString
End Try

Return payloadData
End Function

Function sendUDP(ByVal payload As Byte(), ByVal endPoint As IPEndPoint) As Integer
Dim byteSend As Integer
Dim socketClient As Socket

If (payload IsNot Nothing) AndAlso (endPoint IsNot Nothing) Then
socketClient = New Socket(endPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp)
socketClient.Connect(endPoint)
byteSend = socketClient.Send(payload, 0, payload.Length, SocketFlags.None)

socketClient.Close()
Else
byteSend = 0
End If

Return byteSend
End Function
&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; It is the main method of the class. It must be called after the MAC address has been set. It does not return any code, you can see the result of the operation with the bytesSent and packetSent properties of this class.
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;remarks&gt;&lt;/remarks&gt;
Public Sub wakeIt()
mBytesSent = sendUDP(magicPacket(mMACAddress), mEndPoint)
End Sub
&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; No parameter is required. The new statement just created the IPEndPoint object.
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;remarks&gt;The default IPEndPoint transmit on port 7. Other choices for WOL are port 0 or 9&lt;/remarks&gt;
Sub New()
mEndPoint = New IPEndPoint(IPAddress.Broadcast, 7)
End Sub
&#039;&#039;&#039; &lt;summary&gt;
&#039;&#039;&#039; The IPEndPoint object is created to the specified port
&#039;&#039;&#039; &lt;/summary&gt;
&#039;&#039;&#039; &lt;param name=&quot;epPort&quot;&gt;A valid port number&lt;/param&gt;
&#039;&#039;&#039; &lt;remarks&gt;If the port number is invalid, the IPEndPoint is created to port 7. Ports normally used for WOL are 0, 7 or 9.&lt;/remarks&gt;
Sub New(ByVal epPort As Integer)
If epPort &gt;= 0 AndAlso epPort &lt; 65535 Then
mEndPoint = New IPEndPoint(IPAddress.Broadcast, epPort)
Else
mEndPoint = New IPEndPoint(IPAddress.Broadcast, 7)
End If
End Sub
End Class </pre>

<p>So to call this class you do something like this:</p>
<pre class="brush: vb.net">

Dim WOL As New clsWOL
WOL.macAddress = &quot;00-1E-4F-96-C8-D8&quot;
WOL.wakeIt()
</pre>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;t=WOL+in+VB.net" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=WOL+in+VB.net+-+http://b2l.me/kbkt4+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;title=WOL+in+VB.net" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;title=WOL+in+VB.net" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;title=WOL+in+VB.net" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;t=WOL+in+VB.net" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;title=WOL+in+VB.net" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;title=WOL+in+VB.net&amp;summary=I%20have%20found%20a%20really%20handy%20VB.net%20class%20to%20do%20Wake%20On%20LAN.%C2%A0%20The%20original%20website%20is%20here%3A%0D%0A%0D%0Ahttp%3A%2F%2Fwww.lucamauri.com%2Fsnippet%2Fsnip.aspx%3Fid%3D6%0D%0A%0D%0A%0D%0A%0D%0AThe%20code%20in%20full%20is%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22vb.net%22%5D%0D%0A%0D%0AImports%20System.Net%0D%0AImports%20System.Net.Sockets%0D%0AImports%20System.Text%0D%0A%0D%0APublic%20Class%20clsWOL%0D%0A&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;title=WOL+in+VB.net" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2010/03/wol-in-vb-net/&amp;title=WOL+in+VB.net&amp;body=I%20have%20found%20a%20really%20handy%20VB.net%20class%20to%20do%20Wake%20On%20LAN.%C2%A0%20The%20original%20website%20is%20here%3A%0D%0A%0D%0Ahttp%3A%2F%2Fwww.lucamauri.com%2Fsnippet%2Fsnip.aspx%3Fid%3D6%0D%0A%0D%0A%0D%0A%0D%0AThe%20code%20in%20full%20is%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22vb.net%22%5D%0D%0A%0D%0AImports%20System.Net%0D%0AImports%20System.Net.Sockets%0D%0AImports%20System.Text%0D%0A%0D%0APublic%20Class%20clsWOL%0D%0A" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22WOL%20in%20VB.net%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22I%20have%20found%20a%20really%20handy%20VB.net%20class%20to%20do%20Wake%20On%20LAN.%C2%A0%20The%20original%20website%20is%20here%3A%0D%0A%0D%0Ahttp%3A%2F%2Fwww.lucamauri.com%2Fsnippet%2Fsnip.aspx%3Fid%3D6%0D%0A%0D%0A%0D%0A%0D%0AThe%20code%20in%20full%20is%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22vb.net%22%5D%0D%0A%0D%0AImports%20System.Net%0D%0AImports%20System.Net.Sockets%0D%0AImports%20System.Text%0D%0A%0D%0APublic%20Class%20clsWOL%0D%0A%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2010/03/wol-in-vb-net/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2010/03/wol-in-vb-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Stop Most Robots Posting to your Forms</title>
		<link>http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/</link>
		<comments>http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 09:45:07 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Forms]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=489</guid>
		<description><![CDATA[Sometimes you don&#8217;t want to use captchas or &#8220;are you human questions&#8221; on your forms, well here&#8217;s a simply way to block the vast majority of bots posting to your website forms.

This quick technique is easy to implement and relies on that fact that bots are stupid and pick up on keywords and try to [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you don&#8217;t want to use captchas or &#8220;are you human questions&#8221; on your forms, well here&#8217;s a simply way to block the vast majority of bots posting to your website forms.</p>
<p><span id="more-489"></span></p>
<p><img class="alignleft" style="margin: 10px;" title="Robot (Wall-E)" src="http://gandt.blogs.brynmawr.edu/files/2009/01/wall-e-dancing-robot-plays-mp3s.jpg" alt="" width="130" height="130" />This quick technique is easy to implement and relies on that fact that bots are stupid and pick up on keywords and try to complete all the fields in a form.</p>
<p>The best way to stop bots is to always use a combination of techniques, such as captchas and IP address checking, but this method will help eliminate a lot of junk.</p>
<p>On your form simply include a hidden text field called something generic like &#8220;email&#8221; if you have an email field call it something obscure like &#8220;customcontact&#8221; eg:</p>
<pre class="brush: html">
&lt;form method=&quot;post&quot; action=&quot;/form&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;customcontact&quot; /&gt;
&lt;input type=&quot;hidden&quot; name=&quot;email&quot; /&gt;
&lt;input type=&quot;submit&quot; value=&quot;GO&quot; /&gt;
&lt;/form&gt;
</pre>
<p>The bot will see the hidden email field and try to populate it. On you form validation, check to see if this field is empty:</p>
<pre class="brush: php">

if(empty($_POST[&#039;email&#039;])) {
// you are a human
} else {
// you are a robot
}
</pre>
<p>If the field has something in it, a bot has made the submission so discard it.</p>
<p>If you find that this still doesn&#8217;t work try using CSS instead:</p>
<pre class="brush: html">
&lt;form method=&quot;post&quot; action=&quot;/form&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;customcontact&quot; /&gt;
&lt;input type=&quot;text&quot; name=&quot;email&quot; style=&quot;display:none;&quot;/&gt;
&lt;input type=&quot;submit&quot; value=&quot;GO&quot; /&gt;
&lt;/form&gt;
</pre>
<p>The bot will see the field and try to populate it as it ignores CSS styles, an actual user won&#8217;t see the field so won&#8217;t be able to add anything to it.</p>
<p>This is not a fail-safe way to stop bots submitting your form, but will help reduce a number of rudimentary bot attacks on your forms.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;t=Stop+Most+Robots+Posting+to+your+Forms" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Stop+Most+Robots+Posting+to+your+Forms+-+http://b2l.me/h5bef+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;title=Stop+Most+Robots+Posting+to+your+Forms" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;title=Stop+Most+Robots+Posting+to+your+Forms" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;title=Stop+Most+Robots+Posting+to+your+Forms" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;t=Stop+Most+Robots+Posting+to+your+Forms" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;title=Stop+Most+Robots+Posting+to+your+Forms" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;title=Stop+Most+Robots+Posting+to+your+Forms&amp;summary=Sometimes%20you%20don%27t%20want%20to%20use%20captchas%20or%20%22are%20you%20human%20questions%22%20on%20your%20forms%2C%20well%20here%27s%20a%20simply%20way%20to%20block%20the%20vast%20majority%20of%20bots%20posting%20to%20your%20website%20forms.%0D%0A%0D%0A%0D%0A%0D%0AThis%20quick%20technique%20is%20easy%20to%20implement%20and%20relies%20on%20that%20fact%20that%20bots%20are%20stupid%20and%20pick%20up%20on%20keywords%20and%20tr&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;title=Stop+Most+Robots+Posting+to+your+Forms" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/&amp;title=Stop+Most+Robots+Posting+to+your+Forms&amp;body=Sometimes%20you%20don%27t%20want%20to%20use%20captchas%20or%20%22are%20you%20human%20questions%22%20on%20your%20forms%2C%20well%20here%27s%20a%20simply%20way%20to%20block%20the%20vast%20majority%20of%20bots%20posting%20to%20your%20website%20forms.%0D%0A%0D%0A%0D%0A%0D%0AThis%20quick%20technique%20is%20easy%20to%20implement%20and%20relies%20on%20that%20fact%20that%20bots%20are%20stupid%20and%20pick%20up%20on%20keywords%20and%20tr" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Stop%20Most%20Robots%20Posting%20to%20your%20Forms%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Sometimes%20you%20don%27t%20want%20to%20use%20captchas%20or%20%22are%20you%20human%20questions%22%20on%20your%20forms%2C%20well%20here%27s%20a%20simply%20way%20to%20block%20the%20vast%20majority%20of%20bots%20posting%20to%20your%20website%20forms.%0D%0A%0D%0A%0D%0A%0D%0AThis%20quick%20technique%20is%20easy%20to%20implement%20and%20relies%20on%20that%20fact%20that%20bots%20are%20stupid%20and%20pick%20up%20on%20keywords%20and%20tr%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2010/03/stop-most-robots-posting-to-your-forms/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Move a background image in relation to the mouse</title>
		<link>http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/</link>
		<comments>http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 09:21:52 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=480</guid>
		<description><![CDATA[To add a bit of flare to your site you may want to move a background image in relation to where the users cursor is, this can create some very cool animation.


Using this code snippet can produce some very funky results, if could use it for accessibility highlighting where to mouse is for instance, or [...]]]></description>
			<content:encoded><![CDATA[<p>To add a bit of flare to your site you may want to move a background image in relation to where the users cursor is, this can create some very cool animation.</p>
<p><span id="more-480"></span></p>
<p><img class="alignleft" style="margin: 10px;" src="http://www.anuglymind.co.uk/images/words-repeat.jpg" alt="" width="200" height="200" /></p>
<p>Using this code snippet can produce some very funky results, if could use it for accessibility highlighting where to mouse is for instance, or to create a crude animation.</p>
<p>It works very well when you just want to add a bit of dynamic movement to the site but don&#8217;t want to use flash because of accessbility issues.</p>
<p>We tend to find it works best with tiled backgrounds, as you then never see the clipping where the image ends and it makes it look perspective.</p>
<p>First of all add an id and the initial style to your element, in our example we are going to dynamically move the body background image so we add this:</p>
<pre class="brush: html">

&lt;body id=&quot;doc&quot; style=&quot;background-position:0px 0px&quot;&gt;
</pre>
<p>Then simply include this piece of lovely JavaScript:</p>
<pre class="brush: javascript">

var IE = document.all?true:false

if (!IE) document.captureEvents(Event.MOUSEMOVE)

document.onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s

function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
} else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX
tempY = e.pageY
}

if (tempX &lt; 0){tempX = 0}
if (tempY &lt; 0){tempY = 0}

var pos = tempX + &quot;px &quot; + tempY + &quot;px&quot;;

document.getElementById(&#039;doc&#039;).style.backgroundPosition = pos;

}
</pre>
<p>If you need to you can change the id of the element with the background image or even include delays to create momentum etcetera.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;t=Move+a+background+image+in+relation+to+the+mouse" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Move+a+background+image+in+relation+to+the+mouse+-+http://b2l.me/gsfua+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;title=Move+a+background+image+in+relation+to+the+mouse" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;title=Move+a+background+image+in+relation+to+the+mouse" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;title=Move+a+background+image+in+relation+to+the+mouse" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;t=Move+a+background+image+in+relation+to+the+mouse" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;title=Move+a+background+image+in+relation+to+the+mouse" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;title=Move+a+background+image+in+relation+to+the+mouse&amp;summary=To%20add%20a%20bit%20of%20flare%20to%20your%20site%20you%20may%20want%20to%20move%20a%20background%20image%20in%20relation%20to%20where%20the%20users%20cursor%20is%2C%20this%20can%20create%20some%20very%20cool%20animation.%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0AUsing%20this%20code%20snippet%20can%20produce%20some%20very%20funky%20results%2C%20if%20could%20use%20it%20for%20accessibility%20highlighting%20where%20to%20mouse%20is%20for%20&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;title=Move+a+background+image+in+relation+to+the+mouse" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/&amp;title=Move+a+background+image+in+relation+to+the+mouse&amp;body=To%20add%20a%20bit%20of%20flare%20to%20your%20site%20you%20may%20want%20to%20move%20a%20background%20image%20in%20relation%20to%20where%20the%20users%20cursor%20is%2C%20this%20can%20create%20some%20very%20cool%20animation.%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0AUsing%20this%20code%20snippet%20can%20produce%20some%20very%20funky%20results%2C%20if%20could%20use%20it%20for%20accessibility%20highlighting%20where%20to%20mouse%20is%20for%20" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Move%20a%20background%20image%20in%20relation%20to%20the%20mouse%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22To%20add%20a%20bit%20of%20flare%20to%20your%20site%20you%20may%20want%20to%20move%20a%20background%20image%20in%20relation%20to%20where%20the%20users%20cursor%20is%2C%20this%20can%20create%20some%20very%20cool%20animation.%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0AUsing%20this%20code%20snippet%20can%20produce%20some%20very%20funky%20results%2C%20if%20could%20use%20it%20for%20accessibility%20highlighting%20where%20to%20mouse%20is%20for%20%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2010/02/move-a-background-image-in-relation-to-the-mouse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL AD Group membership</title>
		<link>http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/</link>
		<comments>http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 14:57:55 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Active]]></category>
		<category><![CDATA[AD]]></category>
		<category><![CDATA[Directory]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[membership]]></category>
		<category><![CDATA[Procedure]]></category>
		<category><![CDATA[SP]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Stored]]></category>
		<category><![CDATA[users]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=456</guid>
		<description><![CDATA[Hi all,
I have been working on a way to return Active directory group membership from a linked AD server in SQL.
Its quite hard as you can`t return it from the group &#8211; you have to return it from the user. What i wanted was to return every group within an OU and its members.

I first [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>I have been working on a way to return Active directory group membership from a linked AD server in SQL.</p>
<p>Its quite hard as you can`t return it from the group &#8211; you have to return it from the user. What i wanted was to return every group within an OU and its members.<br />
<span id="more-456"></span><br />
I first found this person and thier code:</p>
<p><a href="http://blog.sdbonline.com/blog/?tag=/sql+server">http://blog.sdbonline.com/blog/?tag=/sql+server</a></p>
<p>So i used this code and modified it somewhat. It now takes many more parameters and returns all group membership from an OU. You obviously have to set up the linked SQL server first.</p>

<p>One of the hardest parts of this was the fact that it seemed to have some kind of limit to how much you can query the AD. To get round this i put a wait in after a certain amount of groups (configured by the parameters). I found that every 500 waiting 2 minutes was the safest root. It also waits 2 minutes to start, in case you have run it recently.</p>
<pre class="brush: sql">
ALTER PROCEDURE [dbo].[sp_getADGroupUsers]
@LDAPRoot nvarchar(200),
@OUGROUP nvarchar(200),
@OUUSERS nvarchar(200),
@Waittime nvarchar(10),
@WaitGap integer,
@ServerName nvarchar(30)

AS

BEGIN
DECLARE @SQLString nvarchar(4000)
DECLARE @group_name nvarchar(500)
DECLARE @group_cursor CURSOR
Declare @GroupSamAccountname nvarchar(100)
declare @i integer

--Create a temp table to hold the results
CREATE TABLE #ADSI (
GroupCN nvarchar(500),
SamAccountname nvarchar(100))

--build an SQL string to return the ADsPath for the requested group
set @SQLString = N&#039;SET @group_cursor = CURSOR STATIC FOR SELECT SUBSTRING(ADsPath,&#039;+ cast(len(@ldaproot)+1 as varchar) + &#039;,LEN(ADsPath))

FROM OPENQUERY(&#039;+ @ServerName +&#039;,&#039;&#039;SELECT ADsPath FROM &#039;&#039;&#039;&#039;&#039; + @LDAPRoot + @ouGROUP + &#039;&#039;&#039;&#039;&#039;
WHERE objectClass = &#039;&#039;&#039;&#039;Group&#039;&#039;&#039;&#039; &#039;&#039;) FOR READ ONLY; OPEN @group_cursor&#039;

--Execute the statement (will return the ADsPath in @group_cursor
EXECUTE sp_executesql @SQLString, N&#039;@group_cursor CURSOR OUTPUT&#039;,
@group_cursor OUTPUT

set @i = 0

FETCH NEXT FROM @group_cursor INTO @group_name
WHILE @@FETCH_STATUS = 0
BEGIN

--work out account name
set @GroupSamAccountname = substring(@group_name, 4, (len(@group_name) - len( @OUGROUP))-4)

--Get data for group
SET @SQLString = N&#039;INSERT INTO #ADSI SELECT &#039;&#039;&#039; + @GroupSamAccountname + &#039;&#039;&#039;,SamAccountname
FROM OPENQUERY(&#039;+ @ServerName +&#039;,&#039;&#039;SELECT ADsPath,
SamAccountname FROM &#039;&#039;&#039;&#039;&#039; + @LDAPRoot + @OUUsers + &#039;&#039;&#039;&#039;&#039;
WHERE objectCategory = &#039;&#039;&#039;&#039;Person&#039;&#039;&#039;&#039; and objectClass = &#039;&#039;&#039;&#039;user&#039;&#039;&#039;&#039;
and memberOf=&#039;&#039;&#039;&#039;&#039; + @group_name + &#039;&#039;&#039;&#039;&#039; &#039;&#039;) &#039;;

--execute the statement
EXECUTE sp_executesql @SQLString;

set @i = @i + 1

IF @i = @waitgap
BEGIN
WAITFOR DELAY @waittime
set @i = 0
END

FETCH NEXT FROM @group_cursor INTO @group_name
END

--return the resultset
--(use DISTINCT as a user might be a member of several groups)
SELECT DISTINCT * FROM #ADSI

--explicitely drop the temp table
DROP TABLE #ADSI
END </pre>

<p>And here is how you call it:</p>
<pre class="brush: sql">
DECLARE @RC int
DECLARE @LDAPRoot nvarchar(200)
DECLARE @FriendlyGroupName nvarchar(200)
DECLARE @OUGROUP nvarchar(200)
DECLARE @OUUSERS nvarchar(200)
declare @waittime nvarchar(10)
declare @waitgap integer
declare @ServerName nvarchar(30)

set @ldaproot = &#039;LDAP://DC.domain.com/&#039;

--Where are the groups you want to return
set @OUGROUP = &#039;OU=groups,DC=Domain,DC=co,DC=uk&#039;
--Where are the users you want to return
set @OUUSERS = &#039;OU=users,DC=domain,DC=co,DC=uk&#039;
--Waiting time between groups
set @waittime = &#039;00:02:00&#039;
--How big are the groups
set @waitgap = 500
--Your AD linked server in SQL
set @ServerName = &#039;ADSI&#039;

EXECUTE @RC = [SystemsIntegration].[dbo].[sp_getADGroupUsers]
@LDAPRoot

,@OUGROUP
,@OUUSERS
,@waittime
,@waitgap
,@ServerName
</pre>
<p>Hope this helps someone,</p>
<p>Dan</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;t=SQL+AD+Group+membership" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=SQL+AD+Group+membership+-+http://b2l.me/fmufx+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;title=SQL+AD+Group+membership" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;title=SQL+AD+Group+membership" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;title=SQL+AD+Group+membership" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;t=SQL+AD+Group+membership" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;title=SQL+AD+Group+membership" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;title=SQL+AD+Group+membership&amp;summary=Hi%20all%2C%0D%0A%0D%0AI%20have%20been%20working%20on%20a%20way%20to%20return%20Active%20directory%20group%20membership%20from%20a%20linked%20AD%20server%20in%20SQL.%0D%0A%0D%0AIts%20quite%20hard%20as%20you%20can%60t%20return%20it%20from%20the%20group%20-%20you%20have%20to%20return%20it%20from%20the%20user.%20What%20i%20wanted%20was%20to%20return%20every%20group%20within%20an%20OU%20and%20its%20members.%0D%0A%0D%0AI%20first%20found%20th&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;title=SQL+AD+Group+membership" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/&amp;title=SQL+AD+Group+membership&amp;body=Hi%20all%2C%0D%0A%0D%0AI%20have%20been%20working%20on%20a%20way%20to%20return%20Active%20directory%20group%20membership%20from%20a%20linked%20AD%20server%20in%20SQL.%0D%0A%0D%0AIts%20quite%20hard%20as%20you%20can%60t%20return%20it%20from%20the%20group%20-%20you%20have%20to%20return%20it%20from%20the%20user.%20What%20i%20wanted%20was%20to%20return%20every%20group%20within%20an%20OU%20and%20its%20members.%0D%0A%0D%0AI%20first%20found%20th" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22SQL%20AD%20Group%20membership%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Hi%20all%2C%0D%0A%0D%0AI%20have%20been%20working%20on%20a%20way%20to%20return%20Active%20directory%20group%20membership%20from%20a%20linked%20AD%20server%20in%20SQL.%0D%0A%0D%0AIts%20quite%20hard%20as%20you%20can%60t%20return%20it%20from%20the%20group%20-%20you%20have%20to%20return%20it%20from%20the%20user.%20What%20i%20wanted%20was%20to%20return%20every%20group%20within%20an%20OU%20and%20its%20members.%0D%0A%0D%0AI%20first%20found%20th%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2010/02/sql-ad-group-membership/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Face Detection with PHP</title>
		<link>http://www.cardboardcoder.com/2009/12/face-detection-with-php/</link>
		<comments>http://www.cardboardcoder.com/2009/12/face-detection-with-php/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 17:13:49 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[GD Lib]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=419</guid>
		<description><![CDATA[A very useful piece of PHP code that will highlight any pictures where a face has been detected.
Heres the first piece of PHP code you will need, it would be best to make this an include:


class Face_Detector {

protected $detection_data;
protected $canvas;
protected $face;
private $reduced_canvas;

public function __construct($detection_file = &#039;detection.dat&#039;) {
if (is_file($detection_file)) {
$this-&#62;detection_data = unserialize(file_get_contents($detection_file));
} else {
throw new Exception(&#34;Couldn&#039;t [...]]]></description>
			<content:encoded><![CDATA[<p>A very useful piece of PHP code that will highlight any pictures where a face has been detected.</p>
<p><span id="more-419"></span>Heres the first piece of PHP code you will need, it would be best to make this an include:</p>
<pre class="brush: php">

class Face_Detector {

protected $detection_data;
protected $canvas;
protected $face;
private $reduced_canvas;

public function __construct($detection_file = &#039;detection.dat&#039;) {
if (is_file($detection_file)) {
$this-&gt;detection_data = unserialize(file_get_contents($detection_file));
} else {
throw new Exception(&quot;Couldn&#039;t load detection data&quot;);
}
//$this-&gt;detection_data = json_decode(file_get_contents(&#039;data.js&#039;));
}

public function face_detect($file) {
if (!is_file($file)) {
throw new Exception(&quot;Can not load $file&quot;);
}

$this-&gt;canvas = imagecreatefromjpeg($file);
$im_width = imagesx($this-&gt;canvas);
$im_height = imagesy($this-&gt;canvas);

//Resample before detection?
$ratio = 0;
$diff_width = 320 - $im_width;
$diff_height = 240 - $im_height;
if ($diff_width &gt; $diff_height) {
$ratio = $im_width / 320;
} else {
$ratio = $im_height / 240;
}

if ($ratio != 0) {
$this-&gt;reduced_canvas = imagecreatetruecolor($im_width / $ratio, $im_height / $ratio);
imagecopyresampled($this-&gt;reduced_canvas, $this-&gt;canvas, 0, 0, 0, 0, $im_width / $ratio, $im_height / $ratio, $im_width, $im_height);

$stats = $this-&gt;get_img_stats($this-&gt;reduced_canvas);
$this-&gt;face = $this-&gt;do_detect_greedy_big_to_small($stats[&#039;ii&#039;], $stats[&#039;ii2&#039;], $stats[&#039;width&#039;], $stats[&#039;height&#039;]);
$this-&gt;face[&#039;x&#039;] *= $ratio;
$this-&gt;face[&#039;y&#039;] *= $ratio;
$this-&gt;face[&#039;w&#039;] *= $ratio;
} else {
$stats = $this-&gt;get_img_stats($this-&gt;canvas);
$this-&gt;face = $this-&gt;do_detect_greedy_big_to_small($stats[&#039;ii&#039;], $stats[&#039;ii2&#039;], $stats[&#039;width&#039;], $stats[&#039;height&#039;]);
}
return ($this-&gt;face[&#039;w&#039;] &gt; 0);
}

public function toJpeg() {
$color = imagecolorallocate($this-&gt;canvas, 255, 0, 0); //red
imagerectangle($this-&gt;canvas, $this-&gt;face[&#039;x&#039;], $this-&gt;face[&#039;y&#039;], $this-&gt;face[&#039;x&#039;]+$this-&gt;face[&#039;w&#039;], $this-&gt;face[&#039;y&#039;]+ $this-&gt;face[&#039;w&#039;], $color);
header(&#039;Content-type: image/jpeg&#039;);
imagejpeg($this-&gt;canvas);
}

public function toJson() {
return &quot;{&#039;x&#039;:&quot; . $this-&gt;face[&#039;x&#039;] . &quot;, &#039;y&#039;:&quot; . $this-&gt;face[&#039;y&#039;] . &quot;, &#039;w&#039;:&quot; . $this-&gt;face[&#039;w&#039;] . &quot;}&quot;;
}

public function getFace() {
return $this-&gt;face;
}

protected function get_img_stats($canvas){
$image_width = imagesx($canvas);
$image_height = imagesy($canvas);
$iis =  $this-&gt;compute_ii($canvas, $image_width, $image_height);
return array(
&#039;width&#039; =&gt; $image_width,
&#039;height&#039; =&gt; $image_height,
&#039;ii&#039; =&gt; $iis[&#039;ii&#039;],
&#039;ii2&#039; =&gt; $iis[&#039;ii2&#039;]
);
}

protected function compute_ii($canvas, $image_width, $image_height ){
$ii_w = $image_width+1;
$ii_h = $image_height+1;
$ii = array();
$ii2 = array();

for($i=0; $i&lt;$ii_w; $i++ ){
$ii[$i] = 0;
$ii2[$i] = 0;
}

for($i=1; $i&lt;$ii_w; $i++ ){
$ii[$i*$ii_w] = 0;
$ii2[$i*$ii_w] = 0;
$rowsum = 0;
$rowsum2 = 0;
for($j=1; $j&lt;$ii_h; $j++ ){                 $rgb = ImageColorAt($canvas, $j, $i);                 $red = ($rgb &gt;&gt; 16) &amp;amp;amp; 0xFF;
$green = ($rgb &gt;&gt; <img src='http://www.cardboardcoder.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> &amp;amp;amp; 0xFF;
$blue = $rgb &amp;amp;amp; 0xFF;
$grey = ( 0.2989*$red + 0.587*$green + 0.114*$blue )&gt;&gt;0;  // this is what matlab uses
$rowsum += $grey;
$rowsum2 += $grey*$grey;

$ii_above = ($i-1)*$ii_w + $j;
$ii_this = $i*$ii_w + $j;

$ii[$ii_this] = $ii[$ii_above] + $rowsum;
$ii2[$ii_this] = $ii2[$ii_above] + $rowsum2;
}
}
return array(&#039;ii&#039;=&gt;$ii, &#039;ii2&#039; =&gt; $ii2);
}

protected function do_detect_greedy_big_to_small( $ii, $ii2, $width, $height ){
$s_w = $width/20.0;
$s_h = $height/20.0;
$start_scale = $s_h &lt; $s_w ? $s_h : $s_w;         $scale_update = 1 / 1.2;         for($scale = $start_scale; $scale &gt; 1; $scale *= $scale_update ){
$w = (20*$scale) &gt;&gt; 0;
$endx = $width - $w - 1;
$endy = $height - $w - 1;
$step = max( $scale, 2 ) &gt;&gt; 0;
$inv_area = 1 / ($w*$w);
for($y = 0; $y &lt; $endy ; $y += $step ){
for($x = 0; $x &lt; $endx ; $x += $step ){                     $passed = $this-&gt;detect_on_sub_image( $x, $y, $scale, $ii, $ii2, $w, $width+1, $inv_area);
if( $passed ) {
return array(&#039;x&#039;=&gt;$x, &#039;y&#039;=&gt;$y, &#039;w&#039;=&gt;$w);
}
} // end x
} // end y
}  // end scale
return null;
}

protected function detect_on_sub_image( $x, $y, $scale, $ii, $ii2, $w, $iiw, $inv_area){
$mean = ( $ii[($y+$w)*$iiw + $x + $w] + $ii[$y*$iiw+$x] - $ii[($y+$w)*$iiw+$x] - $ii[$y*$iiw+$x+$w]  )*$inv_area;
$vnorm =  ( $ii2[($y+$w)*$iiw + $x + $w] + $ii2[$y*$iiw+$x] - $ii2[($y+$w)*$iiw+$x] - $ii2[$y*$iiw+$x+$w]  )*$inv_area - ($mean*$mean);
$vnorm = $vnorm &gt; 1 ? sqrt($vnorm) : 1;

$passed = true;
for($i_stage = 0; $i_stage &lt; count($this-&gt;detection_data); $i_stage++ ){
$stage = $this-&gt;detection_data[$i_stage];
$trees = $stage[0];

$stage_thresh = $stage[1];
$stage_sum = 0;

for($i_tree = 0; $i_tree &lt; count($trees); $i_tree++ ){
$tree = $trees[$i_tree];
$current_node = $tree[0];
$tree_sum = 0;
while( $current_node != null ){
$vals = $current_node[0];
$node_thresh = $vals[0];
$leftval = $vals[1];
$rightval = $vals[2];
$leftidx = $vals[3];
$rightidx = $vals[4];
$rects = $current_node[1];

$rect_sum = 0;
for( $i_rect = 0; $i_rect &lt; count($rects); $i_rect++ ){                         $s = $scale;                         $rect = $rects[$i_rect];                         $rx = ($rect[0]*$s+$x)&gt;&gt;0;
$ry = ($rect[1]*$s+$y)&gt;&gt;0;
$rw = ($rect[2]*$s)&gt;&gt;0;
$rh = ($rect[3]*$s)&gt;&gt;0;
$wt = $rect[4];

$r_sum = ( $ii[($ry+$rh)*$iiw + $rx + $rw] + $ii[$ry*$iiw+$rx] - $ii[($ry+$rh)*$iiw+$rx] - $ii[$ry*$iiw+$rx+$rw] )*$wt;
$rect_sum += $r_sum;
}

$rect_sum *= $inv_area;

$current_node = null;
if( $rect_sum &gt;= $node_thresh*$vnorm ){
if( $rightidx == -1 )
$tree_sum = $rightval;
else
$current_node = $tree[$rightidx];
} else {
if( $leftidx == -1 )
$tree_sum = $leftval;
else
$current_node = $tree[$leftidx];
}
}
$stage_sum += $tree_sum;
}
if( $stage_sum &lt; $stage_thresh ){
return false;
}
}
return true;
}
}
</pre>
<p>To use the code you will require a specific DAT file: <a href="http://svay.com/experiences/face-detection/detection.dat">http://svay.com/experiences/face-detection/detection.dat</a> , the DAT file should be in the same folder as the piece of code as above, if this is not possible you will need to set the location in the piece of PHP code to follow.</p>
<p>Whenever you want to highlight a face in a picture run this piece of PHP code:</p>
<pre class="brush: php">

$detector = new Face_Detector(&#039;detection.dat&#039;);
$detector-&gt;face_detect(&#039;myface.jpg&#039;);
$detector-&gt;toJpeg();
</pre>
<p>Change the &#8220;myface.jpg&#8221; string to the image you wish to check. The result will look something like this:</p>
<p><img class="aligncenter size-full wp-image-420" title="detection" src="http://www.cardboardcoder.com/wp-content/uploads/2009/12/detection.jpg" alt="detection" width="150" height="150" /></p>
<p>If you require a true or false response then return &#8220;$passed&#8221; instead and remove the line that outputs the jpeg image. This code is very useful and could be used for many purposes including:</p>
<ul>
<li>Checking ID card photos (if the code can&#8217;t find the face the picture may not be clear enough)</li>
<li>Sorting images into people and places</li>
<li>Check if images taken by a webcam contain a face</li>
</ul>
<p>If you have any suggestions about the code or any other ideas of its uses, let us know!</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;t=Face+Detection+with+PHP" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Face+Detection+with+PHP+-+http://b2l.me/cj3b4+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;title=Face+Detection+with+PHP" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;title=Face+Detection+with+PHP" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;title=Face+Detection+with+PHP" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;t=Face+Detection+with+PHP" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;title=Face+Detection+with+PHP" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2009/12/face-detection-with-php/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;title=Face+Detection+with+PHP&amp;summary=A%20very%20useful%20piece%20of%20PHP%20code%20that%20will%20highlight%20any%20pictures%20where%20a%20face%20has%20been%20detected.%0D%0A%0D%0AHeres%20the%20first%20piece%20of%20PHP%20code%20you%20will%20need%2C%20it%20would%20be%20best%20to%20make%20this%20an%20include%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22php%22%5D%0D%0A%0D%0Aclass%20Face_Detector%20%7B%0D%0A%0D%0Aprotected%20%24detection_data%3B%0D%0Aprotected%20%24canvas%3B%0D%0Apr&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;title=Face+Detection+with+PHP" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2009/12/face-detection-with-php/&amp;title=Face+Detection+with+PHP&amp;body=A%20very%20useful%20piece%20of%20PHP%20code%20that%20will%20highlight%20any%20pictures%20where%20a%20face%20has%20been%20detected.%0D%0A%0D%0AHeres%20the%20first%20piece%20of%20PHP%20code%20you%20will%20need%2C%20it%20would%20be%20best%20to%20make%20this%20an%20include%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22php%22%5D%0D%0A%0D%0Aclass%20Face_Detector%20%7B%0D%0A%0D%0Aprotected%20%24detection_data%3B%0D%0Aprotected%20%24canvas%3B%0D%0Apr" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Face%20Detection%20with%20PHP%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22A%20very%20useful%20piece%20of%20PHP%20code%20that%20will%20highlight%20any%20pictures%20where%20a%20face%20has%20been%20detected.%0D%0A%0D%0AHeres%20the%20first%20piece%20of%20PHP%20code%20you%20will%20need%2C%20it%20would%20be%20best%20to%20make%20this%20an%20include%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22php%22%5D%0D%0A%0D%0Aclass%20Face_Detector%20%7B%0D%0A%0D%0Aprotected%20%24detection_data%3B%0D%0Aprotected%20%24canvas%3B%0D%0Apr%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2009/12/face-detection-with-php/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2009/12/face-detection-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Create an MD5 Hash the Easy Way in .NET</title>
		<link>http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/</link>
		<comments>http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 16:58:07 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Cryptography]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[VB.net]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=298</guid>
		<description><![CDATA[Creating an MD5 hash seems to take forever in .NET, however you may want to try this quick method instead.
Normally you would need to include security routines for Cryptography and it takes many lines of code to achieve, well try this instead:


&#60;%@ Import Namespace=&#34;System.Web.Security&#34; %&#62;

&#60;%

Dim apikey,hash,secretkey,sign
secretkey = &#34;foo&#34;
apikey = &#34;bar&#34;

sign = secretkey +  apikey + [...]]]></description>
			<content:encoded><![CDATA[<p>Creating an MD5 hash seems to take forever in .NET, however you may want to try this quick method instead.</p>
<p><span id="more-298"></span>Normally you would need to include security routines for Cryptography and it takes many lines of code to achieve, well try this instead:</p>
<pre class="brush: vbnet">

&lt;%@ Import Namespace=&quot;System.Web.Security&quot; %&gt;

&lt;%

Dim apikey,hash,secretkey,sign
secretkey = &quot;foo&quot;
apikey = &quot;bar&quot;

sign = secretkey +  apikey + &quot;string&quot;

hash = FormsAuthentication.HashPasswordForStoringInConfigFile (sign, &quot;MD5&quot;)

%&gt;

&lt;%=hash.ToLower()%&gt;
</pre>
<p>Sneakily using the web security name space instead you can quickly turn any string or strings into a perfect MD5 hash everytime. Much quicker then playing around with cryptography!</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;t=Create+an+MD5+Hash+the+Easy+Way+in+.NET" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Create+an+MD5+Hash+the+Easy+Way+in+.NET+-+http://b2l.me/beb22+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;title=Create+an+MD5+Hash+the+Easy+Way+in+.NET" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;title=Create+an+MD5+Hash+the+Easy+Way+in+.NET" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;title=Create+an+MD5+Hash+the+Easy+Way+in+.NET" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;t=Create+an+MD5+Hash+the+Easy+Way+in+.NET" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;title=Create+an+MD5+Hash+the+Easy+Way+in+.NET" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;title=Create+an+MD5+Hash+the+Easy+Way+in+.NET&amp;summary=Creating%20an%20MD5%20hash%20seems%20to%20take%20forever%20in%20.NET%2C%20however%20you%20may%20want%20to%20try%20this%20quick%20method%20instead.%0D%0A%0D%0ANormally%20you%20would%20need%20to%20include%20security%20routines%20for%20Cryptography%20and%20it%20takes%20many%20lines%20of%20code%20to%20achieve%2C%20well%20try%20this%20instead%3A%0D%0A%0D%0A%5Bsourcecode%3D%22vbnet%22%5D%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%5B%2Fsourcecode%5D%0D&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;title=Create+an+MD5+Hash+the+Easy+Way+in+.NET" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/&amp;title=Create+an+MD5+Hash+the+Easy+Way+in+.NET&amp;body=Creating%20an%20MD5%20hash%20seems%20to%20take%20forever%20in%20.NET%2C%20however%20you%20may%20want%20to%20try%20this%20quick%20method%20instead.%0D%0A%0D%0ANormally%20you%20would%20need%20to%20include%20security%20routines%20for%20Cryptography%20and%20it%20takes%20many%20lines%20of%20code%20to%20achieve%2C%20well%20try%20this%20instead%3A%0D%0A%0D%0A%5Bsourcecode%3D%22vbnet%22%5D%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%5B%2Fsourcecode%5D%0D" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Create%20an%20MD5%20Hash%20the%20Easy%20Way%20in%20.NET%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Creating%20an%20MD5%20hash%20seems%20to%20take%20forever%20in%20.NET%2C%20however%20you%20may%20want%20to%20try%20this%20quick%20method%20instead.%0D%0A%0D%0ANormally%20you%20would%20need%20to%20include%20security%20routines%20for%20Cryptography%20and%20it%20takes%20many%20lines%20of%20code%20to%20achieve%2C%20well%20try%20this%20instead%3A%0D%0A%0D%0A%5Bsourcecode%3D%22vbnet%22%5D%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%0D%0A%5B%2Fsourcecode%5D%0D%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2009/12/create-an-md5-hash-the-easy-way-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display a Resized Image From a Different Site</title>
		<link>http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/</link>
		<comments>http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 10:30:58 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=151</guid>
		<description><![CDATA[Sometimes you may need to display an image from a different website, on your website but in thumbnail form, especially if the image is large or is a static image from a webcam.


&#60;?php

// Set a huge memory limit for this page just incase
ini_set ( &#34;memory_limit&#34;, &#34;48M&#34;);

// Source URL for Image
$filename = &#039;http://www.bbc.co.uk/england/webcams/live/ipswich.jpg&#039;;
// Percent to reduce [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you may need to display an image from a different website, on your website but in thumbnail form, especially if the image is large or is a static image from a webcam.</p>
<p><span id="more-151"></span></p>
<pre class="brush: php">
&lt;?php

// Set a huge memory limit for this page just incase
ini_set ( &quot;memory_limit&quot;, &quot;48M&quot;);

// Source URL for Image
$filename = &#039;http://www.bbc.co.uk/england/webcams/live/ipswich.jpg&#039;;
// Percent to reduce source image to
$percent = 0.5;

// Headers
header(&#039;Content-type: image/jpeg&#039;);
header(&quot;Connection: close&quot;);
header(&quot;Expires: -1&quot;);

// Figure out sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Prepare everything
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Do the resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output the result
imagejpeg($thumb);
imagedestroy($thumb);
imagedestroy($source);

?&gt;
</pre>
<p>This code will resize the live feed image from the BBC website and display the result as a thumbnail (50% of the original size to be precise). It also sets the headers to ensure the image is not cached, changes the memory limit temporarily in case you plan on resizing HD images and free&#8217;s up the memory when it has finished. The code is well commented above for you to change as you need.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;t=Display+a+Resized+Image+From+a+Different+Site" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Display+a+Resized+Image+From+a+Different+Site+-+http://b2l.me/bcn3S+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;title=Display+a+Resized+Image+From+a+Different+Site" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;title=Display+a+Resized+Image+From+a+Different+Site" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;title=Display+a+Resized+Image+From+a+Different+Site" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;t=Display+a+Resized+Image+From+a+Different+Site" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;title=Display+a+Resized+Image+From+a+Different+Site" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;title=Display+a+Resized+Image+From+a+Different+Site&amp;summary=Sometimes%20you%20may%20need%20to%20display%20an%20image%20from%20a%20different%20website%2C%20on%20your%20website%20but%20in%20thumbnail%20form%2C%20especially%20if%20the%20image%20is%20large%20or%20is%20a%20static%20image%20from%20a%20webcam.%0D%0A%0D%0A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22php%22%5D%0D%0A%0D%0A%5B%2Fsourcecode%5D%0D%0A%0D%0AThis%20code%20will%20resize%20the%20live%20feed%20image%20from%20the%20BBC%20website%20and%20d&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;title=Display+a+Resized+Image+From+a+Different+Site" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/&amp;title=Display+a+Resized+Image+From+a+Different+Site&amp;body=Sometimes%20you%20may%20need%20to%20display%20an%20image%20from%20a%20different%20website%2C%20on%20your%20website%20but%20in%20thumbnail%20form%2C%20especially%20if%20the%20image%20is%20large%20or%20is%20a%20static%20image%20from%20a%20webcam.%0D%0A%0D%0A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22php%22%5D%0D%0A%0D%0A%5B%2Fsourcecode%5D%0D%0A%0D%0AThis%20code%20will%20resize%20the%20live%20feed%20image%20from%20the%20BBC%20website%20and%20d" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Display%20a%20Resized%20Image%20From%20a%20Different%20Site%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Sometimes%20you%20may%20need%20to%20display%20an%20image%20from%20a%20different%20website%2C%20on%20your%20website%20but%20in%20thumbnail%20form%2C%20especially%20if%20the%20image%20is%20large%20or%20is%20a%20static%20image%20from%20a%20webcam.%0D%0A%0D%0A%0D%0A%0D%0A%5Bsourcecode%20language%3D%22php%22%5D%0D%0A%0D%0A%5B%2Fsourcecode%5D%0D%0A%0D%0AThis%20code%20will%20resize%20the%20live%20feed%20image%20from%20the%20BBC%20website%20and%20d%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2009/12/display-a-resized-image-from-a-different-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vb.net Removing NTFS Permissions and Inheritance</title>
		<link>http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/</link>
		<comments>http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 13:58:56 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[NTFS]]></category>
		<category><![CDATA[Permissions]]></category>
		<category><![CDATA[VB.net]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=208</guid>
		<description><![CDATA[Ever needed to remove NTFS permission&#8217;s in VB.net

Here is a short function to remove permissions off a file:

Private Function RemovePermission(ByVal Foldername As String, ByVal StrSIDorUser As String, ByVal strtype As String) As Boolean
Dim oSecurity As New FileSecurity
Try
oSecurity = File.GetAccessControl(Foldername)
Dim DirSecRules As AuthorizationRuleCollection = oSecurity.GetAccessRules(True, True, GetType(System.Security.Principal.SecurityIdentifier))
For Each DirSecRule As FileSystemAccessRule In DirSecRules
If String.Compare(strtype, &#34;SID&#34;, True) [...]]]></description>
			<content:encoded><![CDATA[<p>Ever needed to remove NTFS permission&#8217;s in VB.net</p>
<p><span id="more-208"></span></p>
<p>Here is a short function to remove permissions off a file:</p>
<pre class="brush: vbnet">
Private Function RemovePermission(ByVal Foldername As String, ByVal StrSIDorUser As String, ByVal strtype As String) As Boolean
Dim oSecurity As New FileSecurity
Try
oSecurity = File.GetAccessControl(Foldername)
Dim DirSecRules As AuthorizationRuleCollection = oSecurity.GetAccessRules(True, True, GetType(System.Security.Principal.SecurityIdentifier))
For Each DirSecRule As FileSystemAccessRule In DirSecRules
If String.Compare(strtype, &quot;SID&quot;, True) = 0 Then
If String.Compare(DirSecRule.IdentityReference.ToString, StrSIDorUser) = 0 Then
&#039;oSecurity.RemoveAccessRuleAll(DirSecRule)
oSecurity.RemoveAccessRule(DirSecRule)
Exit For
End If
Else
Dim account As NTAccount = CType(DirSecRule.IdentityReference.Translate(GetType(NTAccount)), NTAccount)
If String.Compare(account.ToString, StrSIDorUser, True) = 0 Then
&#039;oSecurity.RemoveAccessRuleAll(DirSecRule)

oSecurity.RemoveAccessRuleSpecific(DirSecRule)
Exit For
End If
End If
Next
File.SetAccessControl(Foldername, oSecurity)
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
oSecurity = Nothing
End Try
End Function
</pre>
<p>Now before you run this there is two things to note. Firstly you can pass it either a SID or an Samaccountname to remove. Either way just specify it when you call the function. Second thing is i have found inheritance to be a little bit of a pain.</p>

<p>So here is a function to remove inheritance from a folder:</p>
<pre class="brush: vbnet">
Public Sub RemoveInheritance(ByVal Path As String)
Dim dInfo As New DirectoryInfo(Path)
Dim ds2 As DirectorySecurity = dInfo.GetAccessControl()

ds2.SetAccessRule((New FileSystemAccessRule(&quot;BUILTIN\ADMINISTRATORS&quot;, FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.InheritOnly, AccessControlType.Allow)))
ds2.AddAccessRule(New FileSystemAccessRule(&quot;BUILTIN\ADMINISTRATORS&quot;, FileSystemRights.FullControl, (InheritanceFlags.ContainerInherit + InheritanceFlags.ObjectInherit), PropagationFlags.InheritOnly, AccessControlType.Allow))

ds2.SetAccessRuleProtection(True, False)
dInfo.SetAccessControl(ds2)
dInfo = Nothing
End Sub
</pre>
<p>The interesting line is this one:</p>
<p>ds2.SetAccessRuleProtection(True, False)</p>
<p>The first Boolean sets protects the folder from inheritance. The second one is only used if the first is true. If set to false it will remove all inherited rules that were created. If set to true it will keep them as copies. As you can see here i opted for remove. It was easier for me to this.</p>
<p>If you do remove, make sure there is still an account with full rights to the file. As you can see here in the same function i add builtin\administrators to have full control. This is to stop all the permissions being removed.</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;t=Vb.net+Removing+NTFS+Permissions+and+Inheritance" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Vb.net+Removing+NTFS+Permissions+and+Inheritance+-+http://b2l.me/a765a+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;title=Vb.net+Removing+NTFS+Permissions+and+Inheritance" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;title=Vb.net+Removing+NTFS+Permissions+and+Inheritance" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;title=Vb.net+Removing+NTFS+Permissions+and+Inheritance" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;t=Vb.net+Removing+NTFS+Permissions+and+Inheritance" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;title=Vb.net+Removing+NTFS+Permissions+and+Inheritance" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;title=Vb.net+Removing+NTFS+Permissions+and+Inheritance&amp;summary=Ever%20needed%20to%20remove%20NTFS%20permission%27s%20in%20VB.net%0D%0A%0D%0A%0D%0A%0D%0AHere%20is%20a%20short%20function%20to%20remove%20permissions%20off%20a%20file%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%27vbnet%27%5D%0D%0APrivate%20Function%20RemovePermission%28ByVal%20Foldername%20As%20String%2C%20ByVal%20StrSIDorUser%20As%20String%2C%20ByVal%20strtype%20As%20String%29%20As%20Boolean%0D%0ADim%20oSecurity%20As%20New%20&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;title=Vb.net+Removing+NTFS+Permissions+and+Inheritance" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/&amp;title=Vb.net+Removing+NTFS+Permissions+and+Inheritance&amp;body=Ever%20needed%20to%20remove%20NTFS%20permission%27s%20in%20VB.net%0D%0A%0D%0A%0D%0A%0D%0AHere%20is%20a%20short%20function%20to%20remove%20permissions%20off%20a%20file%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%27vbnet%27%5D%0D%0APrivate%20Function%20RemovePermission%28ByVal%20Foldername%20As%20String%2C%20ByVal%20StrSIDorUser%20As%20String%2C%20ByVal%20strtype%20As%20String%29%20As%20Boolean%0D%0ADim%20oSecurity%20As%20New%20" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Vb.net%20Removing%20NTFS%20Permissions%20and%20Inheritance%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Ever%20needed%20to%20remove%20NTFS%20permission%27s%20in%20VB.net%0D%0A%0D%0A%0D%0A%0D%0AHere%20is%20a%20short%20function%20to%20remove%20permissions%20off%20a%20file%3A%0D%0A%0D%0A%5Bsourcecode%20language%3D%27vbnet%27%5D%0D%0APrivate%20Function%20RemovePermission%28ByVal%20Foldername%20As%20String%2C%20ByVal%20StrSIDorUser%20As%20String%2C%20ByVal%20strtype%20As%20String%29%20As%20Boolean%0D%0ADim%20oSecurity%20As%20New%20%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2009/12/vb-net-removing-ntfs-permissions-and-inheritance/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Grab Wallpaper (or any image) from Google on-the-fly</title>
		<link>http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/</link>
		<comments>http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 10:30:13 +0000</pubDate>
		<dc:creator>matthew</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.cardboardcoder.com/?p=141</guid>
		<description><![CDATA[Sometimes quite handy, this code snippet allows you to display an image from a Google image search on-the-fly. This means the image will always be up-to-date and often what you were expecting  

&#60;?php

$term = &#34;metal gear solid 4: guns of the patriots&#34;;

$term = preg_replace(&#039;/ /&#039;, &#039;%20&#039;, $term);

$url = &#34;http://ajax.googleapis.com/ajax/services/search/images?v=1.0&#38;q=&#34;.$term.&#34;%20wallpaper%20&#38;imgsz=huge&#38;as_filetype=jpg&#38;key=MYKEY&#38;rsz=large&#34;;
$subject = $str;
$subject = preg_replace(&#039;/.*?&#34;unescapedUrl&#34;:&#34;/&#039;, &#039;&#039;, [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes quite handy, this code snippet allows you to display an image from a Google image search on-the-fly. This means the image will always be up-to-date and often what you were expecting <img src='http://www.cardboardcoder.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><span id="more-141"></span></p>
<pre class="brush: php">&lt;?php

$term = &quot;metal gear solid 4: guns of the patriots&quot;;

$term = preg_replace(&#039;/ /&#039;, &#039;%20&#039;, $term);

$url = &quot;http://ajax.googleapis.com/ajax/services/search/images?v=1.0&amp;q=&quot;.$term.&quot;%20wallpaper%20&amp;imgsz=huge&amp;as_filetype=jpg&amp;key=MYKEY&amp;rsz=large&quot;;
$subject = $str;
$subject = preg_replace(&#039;/.*?&quot;unescapedUrl&quot;:&quot;/&#039;, &#039;&#039;, $str);
$subject = preg_replace(&quot;/.jpg.*/&quot;, &#039;&#039; , $subject);
echo &quot;&lt;img src=&quot;&quot;.$subject.&quot;.jpg&quot; alt=&quot;&quot; /&gt;&quot;;
?&gt;</pre>
<p>This code will display the image in HTML from the term you provide. You must obtain a Google API key first and put it in place of &#8216;MYKEY&#8217;, but feel free to change the search term to whatever you like. You can also change the size of the image to search for to &#8217;small&#8217; , &#8216;medium&#8217; or &#8216;large&#8217; from where it currently says &#8216;huge&#8217;. The &#8216;rsz&#8217; value is best kept set to &#8216;large&#8217; as this is the size of the pool of results it will choose the image from.</p>
<p>This code could be adapted to display multiple images, use the image as a background image or whatever you require to be honest, have fun!</p>


<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand sexy-bookmarks-center">
<ul class="socials">
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?u=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;t=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly+-+http://b2l.me/a2ycy+(via+@cardboardcoder)" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;title=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="sexy-delicious">
			<a href="http://del.icio.us/post?url=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;title=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-reddit">
			<a href="http://reddit.com/submit?url=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;title=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="sexy-myspace">
			<a href="http://www.myspace.com/Modules/PostTo/Pages/?u=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;t=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly" rel="nofollow" class="external" title="Post this to MySpace">Post this to MySpace</a>
		</li>
		<li class="sexy-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;title=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="sexy-technorati">
			<a href="http://technorati.com/faves?add=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="sexy-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;title=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly&amp;summary=Sometimes%20quite%20handy%2C%20this%20code%20snippet%20allows%20you%20to%20display%20an%20image%20from%20a%20Google%20image%20search%20on-the-fly.%20This%20means%20the%20image%20will%20always%20be%20up-to-date%20and%20often%20what%20you%20were%20expecting%20%3B-%29%0D%0A%0D%0A%0D%0A%5Bsourcecode%20language%3D%27php%27%5D%5B%2Fsourcecode%5D%0D%0AThis%20code%20will%20display%20the%20image%20in%20HTML%20from%20the%20term%20yo&amp;source=Cardboard Coder" rel="nofollow" class="external" title="Share this on Linkedin">Share this on Linkedin</a>
		</li>
		<li class="sexy-google">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;title=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly" rel="nofollow" class="external" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-pingfm">
			<a href="http://ping.fm/ref/?link=http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/&amp;title=Grab+Wallpaper+%28or+any+image%29+from+Google+on-the-fly&amp;body=Sometimes%20quite%20handy%2C%20this%20code%20snippet%20allows%20you%20to%20display%20an%20image%20from%20a%20Google%20image%20search%20on-the-fly.%20This%20means%20the%20image%20will%20always%20be%20up-to-date%20and%20often%20what%20you%20were%20expecting%20%3B-%29%0D%0A%0D%0A%0D%0A%5Bsourcecode%20language%3D%27php%27%5D%5B%2Fsourcecode%5D%0D%0AThis%20code%20will%20display%20the%20image%20in%20HTML%20from%20the%20term%20yo" rel="nofollow" class="external" title="Ping this on Ping.fm">Ping this on Ping.fm</a>
		</li>
		<li class="sexy-mail">
			<a href="mailto:?subject=%22Grab%20Wallpaper%20%28or%20any%20image%29%20from%20Google%20on-the-fly%22&amp;body=I%20thought%20this%20article%20might%20interest%20you.%0A%0A%22Sometimes%20quite%20handy%2C%20this%20code%20snippet%20allows%20you%20to%20display%20an%20image%20from%20a%20Google%20image%20search%20on-the-fly.%20This%20means%20the%20image%20will%20always%20be%20up-to-date%20and%20often%20what%20you%20were%20expecting%20%3B-%29%0D%0A%0D%0A%0D%0A%5Bsourcecode%20language%3D%27php%27%5D%5B%2Fsourcecode%5D%0D%0AThis%20code%20will%20display%20the%20image%20in%20HTML%20from%20the%20term%20yo%22%0A%0AYou%20can%20read%20the%20full%20article%20here%3A%20http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://www.cardboardcoder.com/2009/12/grab-wallpaper-or-any-image-from-google-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
