<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr - pckujawa</title>
<link>http://snipplr.com/users/pckujawa</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Tue, 21 May 2013 19:26:37 GMT</pubDate>
<item>
<title>(Python) Getting shovel to work in windows so python methods can be run like individual executables</title>
<link>http://snipplr.com/view/66267/getting-shovel-to-work-in-windows-so-python-methods-can-be-run-like-individual-executables/</link>
<description><![CDATA[ <p>I had hear about a method to run a method like an executable, with the arguments being passed in from the commandline. Apparently, Ruby has this with the Rake project. Well, Python has it with [Shovel](http://devblog.seomoz.org/2012/03/shovel-rake-for-python). Only the instructions didn't work for me on windows, so I had to create a batch script to call `shovel` correctly.

So here's my setup. I installed shovel using `easy_install shovel`, which placed it in my python scripts folder (C:\Python27\Scripts, which is in my PATH). I created 'shovel.bat' (see source) in the same folder. So now I can call `shovel` from anywhere and it will call my batch file, passing the parameters into shovel.

For completeness, here is my working directory structure (note the subfolder called shovel):

	D:.
	│   song log.log
	│   Untitled_10.mp3
	│   Untitled_11.mp3
	│   Untitled_2.mp3
	│   Untitled_3.mp3
	│   Untitled_4.mp3
	│   Untitled_5.mp3
	│   Untitled_6.mp3
	│   Untitled_7.mp3
	│   Untitled_8.mp3
	│   Untitled_9.mp3
	│
	└───shovel
	        tasks.py

My python script is incomplete but can be run by shovel using `shovel tasks.extractSongInfo "log file name.log"` from the directory above the 'shovel' directory. Here's the script:


	from shovel import task
	
	@task
	def extractSongInfo(logFile):
	    """Given a log file with lines like
	"{date}	INFO	 Currently playing - Song: {songName} - Artist: {artist} - Length: {numSeconds}"
	return a collection of extracted info."""
	    opId = "Extracting song info" # operation ID
	    print opId
	    print 'Done: ' + opId</p> ]]></description>
<pubDate>Sun, 22 Jul 2012 07:44:22 GMT</pubDate>
<guid>http://snipplr.com/view/66267/getting-shovel-to-work-in-windows-so-python-methods-can-be-run-like-individual-executables/</guid>
</item>
<item>
<title>(C#) Get the MAC (Physical) address from a device at the specified IP address</title>
<link>http://snipplr.com/view/54687/get-the-mac-physical-address-from-a-device-at-the-specified-ip-address/</link>
<description><![CDATA[ <p>This is about the simplest way I've found. See [this](http://stackoverflow.com/questions/1092463/getting-the-mac-address-of-the-remote-host) and [this](http://stackoverflow.com/questions/1092379/want-to-get-mac-address-of-remote-pc/1092392#1092392) at StackOverflow for more info.</p> ]]></description>
<pubDate>Wed, 01 Jun 2011 08:50:09 GMT</pubDate>
<guid>http://snipplr.com/view/54687/get-the-mac-physical-address-from-a-device-at-the-specified-ip-address/</guid>
</item>
<item>
<title>(C#) Add the Console as a TraceListener (to have Trace messages treated as Console output)</title>
<link>http://snipplr.com/view/38306/add-the-console-as-a-tracelistener-to-have-trace-messages-treated-as-console-output/</link>
<description><![CDATA[ <p>This is particularly useful for unit testing, but you could do it anywhere in your code.</p> ]]></description>
<pubDate>Wed, 04 Aug 2010 03:00:55 GMT</pubDate>
<guid>http://snipplr.com/view/38306/add-the-console-as-a-tracelistener-to-have-trace-messages-treated-as-console-output/</guid>
</item>
<item>
<title>(C#) Calculate a CRC32 like the one used in zip files</title>
<link>http://snipplr.com/view/37249/calculate-a-crc32-like-the-one-used-in-zip-files/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Wed, 14 Jul 2010 03:33:44 GMT</pubDate>
<guid>http://snipplr.com/view/37249/calculate-a-crc32-like-the-one-used-in-zip-files/</guid>
</item>
<item>
<title>(C#) Check if a string can be represented as ASCII</title>
<link>http://snipplr.com/view/35806/check-if-a-string-can-be-represented-as-ascii/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Thu, 17 Jun 2010 02:52:04 GMT</pubDate>
<guid>http://snipplr.com/view/35806/check-if-a-string-can-be-represented-as-ascii/</guid>
</item>
<item>
<title>(C#) Encrypting passwords and other sensitive information in .NET</title>
<link>http://snipplr.com/view/35568/encrypting-passwords-and-other-sensitive-information-in-net/</link>
<description><![CDATA[ <p>If you want to serialize a password in some custom object you are working with, create another member that is the encrypted bytes and serialize/deserialize that.

For simply encrypting/decrypting a file, you can use [System.IO.File.Encrypt](http://msdn.microsoft.com/en-us/library/system.io.file.encrypt.aspx)/Decrypt.</p> ]]></description>
<pubDate>Mon, 07 Jun 2010 15:18:34 GMT</pubDate>
<guid>http://snipplr.com/view/35568/encrypting-passwords-and-other-sensitive-information-in-net/</guid>
</item>
<item>
<title>(C#) ListView with re-ordering through drag and drop</title>
<link>http://snipplr.com/view/33427/listview-with-reordering-through-drag-and-drop/</link>
<description><![CDATA[ <p>Microsoft has acknowledged (see URL) that the lack of this functionality is an error. The extended control code below adds reordering to a ListView. It works with multiple items as well as single items.

See also:
[http://www.codeproject.com/KB/list/dragdroplistviewreorder1.aspx](http://www.codeproject.com/KB/list/dragdroplistviewreorder1.aspx).</p> ]]></description>
<pubDate>Wed, 28 Apr 2010 11:39:54 GMT</pubDate>
<guid>http://snipplr.com/view/33427/listview-with-reordering-through-drag-and-drop/</guid>
</item>
<item>
<title>(C#) Sending emails (particularly with gmail and google apps for domains)</title>
<link>http://snipplr.com/view/32573/sending-emails-particularly-with-gmail-and-google-apps-for-domains/</link>
<description><![CDATA[ <p>For both gmail and gApps, use smtp.gmail.com on port 25 with SSL and NetworkCredentials.

Neither can send email to their own address, but they can send to other addresses.

[NLog](http://nlog-project.org/) has [an example](http://nlog-project.org/wiki/Using_NLog_with_GMail) of how to automatically send emails in order to log info from an app.</p> ]]></description>
<pubDate>Wed, 21 Apr 2010 10:44:27 GMT</pubDate>
<guid>http://snipplr.com/view/32573/sending-emails-particularly-with-gmail-and-google-apps-for-domains/</guid>
</item>
<item>
<title>(C#) Byte Swapping Structs For Conversion From Big To Little Endian (Byte Order)</title>
<link>http://snipplr.com/view/32482/byte-swapping-structs-for-conversion-from-big-to-little-endian-byte-order/</link>
<description><![CDATA[ <p>See the URL for my question and answer on StackOverflow.</p> ]]></description>
<pubDate>Tue, 20 Apr 2010 16:03:34 GMT</pubDate>
<guid>http://snipplr.com/view/32482/byte-swapping-structs-for-conversion-from-big-to-little-endian-byte-order/</guid>
</item>
<item>
<title>(C#) Add index numbers to each row header in a DataGridView</title>
<link>http://snipplr.com/view/31065/add-index-numbers-to-each-row-header-in-a-datagridview/</link>
<description><![CDATA[ <p>`w_Dgv` is the name of the DataGridView control.</p> ]]></description>
<pubDate>Wed, 07 Apr 2010 12:15:42 GMT</pubDate>
<guid>http://snipplr.com/view/31065/add-index-numbers-to-each-row-header-in-a-datagridview/</guid>
</item>
<item>
<title>(C#) Converting MethodInfo into a delegate instance to improve performance</title>
<link>http://snipplr.com/view/29683/converting-methodinfo-into-a-delegate-instance-to-improve-performance/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Fri, 12 Mar 2010 10:13:43 GMT</pubDate>
<guid>http://snipplr.com/view/29683/converting-methodinfo-into-a-delegate-instance-to-improve-performance/</guid>
</item>
<item>
<title>(C#) Persisting values in an application between executions and upgrades (.NET)</title>
<link>http://snipplr.com/view/29302/persisting-values-in-an-application-between-executions-and-upgrades-net/</link>
<description><![CDATA[ <p>Read the [best article on the subject - Exploring Secrets of Persistent Application Settings](http://www.devx.com/dotnet/Article/33944/1954) - and then the following links if desired. (Note, I recommend reading [this forum post about settings not being upgraded](http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/790980e8-eb89-492c-976b-4f93dc7c1caf/).)

It might help to understand [What is app.config for?](http://stackoverflow.com/questions/1431742/what-is-app-config-for)

Also of note: [Saving out a Form's Size and Location using the Application Settings feature](http://blogs.msdn.com/rprabhu/archive/2005/11/28/497792.aspx). Be sure to read the first couple of comments as well.

Lastly, if you are interested in import/export functionality, check out [my post on the subject](http://stackoverflow.com/questions/2389290/how-to-load-a-separate-application-settings-file-dynamically-and-merge-with-curre).</p> ]]></description>
<pubDate>Thu, 04 Mar 2010 17:08:30 GMT</pubDate>
<guid>http://snipplr.com/view/29302/persisting-values-in-an-application-between-executions-and-upgrades-net/</guid>
</item>
<item>
<title>(C#) Basic insert and select commands for SQLite in .NET</title>
<link>http://snipplr.com/view/29247/basic-insert-and-select-commands-for-sqlite-in-net/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Wed, 03 Mar 2010 17:38:15 GMT</pubDate>
<guid>http://snipplr.com/view/29247/basic-insert-and-select-commands-for-sqlite-in-net/</guid>
</item>
<item>
<title>(C#) Hex edit control for .NET GUI</title>
<link>http://snipplr.com/view/28343/hex-edit-control-for-net-gui/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Mon, 15 Feb 2010 13:35:13 GMT</pubDate>
<guid>http://snipplr.com/view/28343/hex-edit-control-for-net-gui/</guid>
</item>
<item>
<title>(C#) .NET 4.0 and System.Threading.Tasks</title>
<link>http://snipplr.com/view/28339/net-40-and-systemthreadingtasks/</link>
<description><![CDATA[ <p>See URL.</p> ]]></description>
<pubDate>Mon, 15 Feb 2010 11:38:15 GMT</pubDate>
<guid>http://snipplr.com/view/28339/net-40-and-systemthreadingtasks/</guid>
</item>
<item>
<title>(C#) Listening for and receiving UDP packets on a particular local IP and port</title>
<link>http://snipplr.com/view/28245/listening-for-and-receiving-udp-packets-on-a-particular-local-ip-and-port/</link>
<description><![CDATA[ <p>For some reason, the only .NET way to listen for UDP packets seems to be the Bind and Receive(Async) methods of the Socket class. The Listen method won't work with UDP in my tests.

As for releasing the Socket correctly, [this forum post](http://social.msdn.microsoft.com/Forums/en-US/netfxnetcom/thread/d54bf574-aa1a-4796-9b21-c9b91607b0fe) explains that you must call Socket.Shutdown instead of Socket.Close (it also says to call Socket.Disconnect(true), but I get exceptions when I do that). If you want to reuse the local endpoint (IP and port), then do Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);

While debugging Socket issues, it's helpful to have a command-line open and use the netstat tool (e.g. "netstat -a -p UDP" to show all UDP sockets on all local interfaces).</p> ]]></description>
<pubDate>Fri, 12 Feb 2010 11:02:25 GMT</pubDate>
<guid>http://snipplr.com/view/28245/listening-for-and-receiving-udp-packets-on-a-particular-local-ip-and-port/</guid>
</item>
<item>
<title>(C#) Obfuscating .NET code so as to hide implementation details from public view (using BabelObfuscator)</title>
<link>http://snipplr.com/view/28194/obfuscating-net-code-so-as-to-hide-implementation-details-from-public-view-using-babelobfuscator/</link>
<description><![CDATA[ <p>If you weren't already aware, you can use a product like [Reflector.NET](http://www.red-gate.com/products/reflector/) to see all of the source code (that's right, the code) of a .NET assembly (DLL, EXE, etc). This is a real problem when your code is proprietary, especially when you might have security implementations in the code. Thus, there is often a need to hide the implementation details - enter obfucation.

There is a [article on and list of obfuscators from C# 411](http://www.csharp411.com/net-obfuscators/) which explains the situation better. From my research, I decided to settle on the free and open source [Babel Obfuscator](http://code.google.com/p/babelobfuscator/). Part of the decision process was seeing it in action, which is especially easy when you install the [Babel add-in for Reflector](http://www.jasonhaley.com/blog/post/2009/08/18/ReflectorBabel-Addin.aspx).

Once you've decided that Babel is for you, the code below automates the process when added to the post-build event of your assembly. The parameters and settings are up to you, but this baseline should do everything you'll need.</p> ]]></description>
<pubDate>Thu, 11 Feb 2010 13:59:34 GMT</pubDate>
<guid>http://snipplr.com/view/28194/obfuscating-net-code-so-as-to-hide-implementation-details-from-public-view-using-babelobfuscator/</guid>
</item>
<item>
<title>(C#) Get the network interface card (NIC) from a known MAC address (and get the IP addresses on that NIC)</title>
<link>http://snipplr.com/view/28193/get-the-network-interface-card-nic-from-a-known-mac-address-and-get-the-ip-addresses-on-that-nic/</link>
<description><![CDATA[ <p>The code shows how to take a known MAC (e.g. "00:00:00:11:22:33") and locate the NIC which has that MAC. Note that the built-in MAC class for .NET is called PhysicalAddress (in System.Net.NetworkInformation). PhysicalAddress.Parse can take a string, so long as it has only numbers or numbers and dashes (-). We normally use colons (:) instead of dashes, so that's why I do a .Replace().

The last part of the code retrieves the IP Addresses associated with the selected NIC.</p> ]]></description>
<pubDate>Thu, 11 Feb 2010 13:48:57 GMT</pubDate>
<guid>http://snipplr.com/view/28193/get-the-network-interface-card-nic-from-a-known-mac-address-and-get-the-ip-addresses-on-that-nic/</guid>
</item>
<item>
<title>(C#) Bind a socket (including UdpClient and TcpClient) to a local network interface card (NIC)</title>
<link>http://snipplr.com/view/28192/bind-a-socket-including-udpclient-and-tcpclient-to-a-local-network-interface-card-nic/</link>
<description><![CDATA[ <p>If you are using a UdpClient or TcpClient, you have access to the internal Socket which either type uses. Unfortunately, if you try to Bind that Socket to a local Endpoint (IPAddress and Port), you will probably get a SocketException. The solution I found is to create the Socket independently, then assign that instance to the UdpClient (as shown in the code) or TcpClient (changing the Socket parameters, of course).</p> ]]></description>
<pubDate>Thu, 11 Feb 2010 13:41:21 GMT</pubDate>
<guid>http://snipplr.com/view/28192/bind-a-socket-including-udpclient-and-tcpclient-to-a-local-network-interface-card-nic/</guid>
</item>
<item>
<title>(C#) Enumerate all controls and sub-controls in a windows form</title>
<link>http://snipplr.com/view/27564/enumerate-all-controls-and-subcontrols-in-a-windows-form/</link>
<description><![CDATA[ <p>Found in the above URL. Requires extension methods (C# 3.0+).</p> ]]></description>
<pubDate>Tue, 02 Feb 2010 11:03:02 GMT</pubDate>
<guid>http://snipplr.com/view/27564/enumerate-all-controls-and-subcontrols-in-a-windows-form/</guid>
</item>
</channel>
</rss>