By BoLOBOOLNE payday loans

My Love-Hate Relationship with Composing

Posted: February 18th, 2011 | Filed under: Composing, Music
Author:
No Comments →
Disclaimer: I don’t know all that much about music. I know enough to be dangerous. Some of the things I may say could be incorrect, incomplete or misleading. I’m sorry if they are, it is not done intentionally, please let me know if I’ve said something wrong.

I recently decided to update my About page which was hopelessly behind. Anyway, as I (for some reason) chose to admit my failings at composing I thought it only made sense to talk about it a little.

For one, allow me to say that I’m really into Jazz. Don’t get me wrong, I love listening to other types of music (especially classical) but so far the only thing I really enjoy playing is jazz. Jazz occupies a large spectrum of styles and what I most like is Modal Jazz, Hard Bop, and Bebop. If you’re interested, More about jazz styles.

Because of my interest in jazz I had to learn a lot of theory including a little of an understanding of modes and composition just to be able to play some. I always loved the creative side of any pursuit, and so diving into composing only seemed natural. The problem with composing is that it’s hard. In concept I figured it had to be fairly simple, I mean, I whistle a new tune that doesn’t sound bad at the drop of a hat. How hard can it be to translate that to paper and stretch it out some?

Read the rest of this entry »

Tags: , ,

Using my Service Locator / IoC in IronPython

Posted: February 10th, 2011 | Filed under: .NET, IronPython, Programming, Software Design
Author:
No Comments →

I’m big on Dependency Injection. I would argue it makes application development easier, faster and more extensible. I realize that sometimes this comes at a cost of a little more challenge in debugging and a performance hit caused by the extra abstraction, but to me it’s an acceptable cost. At least for the type of work I’m doing lately. I’ve written a lot about how I got my configuration files working in the IronPython console and I figured I’d take a second and pass on the very simple but very handy locator module I’ve created to use in IronPython.

We use an Inversion of Control Container (IoC) to accomplish our Dependency Injection. The key thing I suppose to realize, if you’re not familiar with this model, is that access to my full library of classes through IronPython was useless if I couldn’t get my IoC working. The container handles all of the Dependency Injection for me automatically; it’s part of both how my configuration is setup as well as how our IoC works. I’d either need to write a very long and annoying module that injected everything by hand (out of the question!) or get my IoC into IronPython. Once I got the ConfigurationManager Injection working the way I needed, bringing through the IoC was easy.

This is basically the entirety of my locator module. This just loads up the default container which works for a huge majority of the work I need to do. But I could of course request a different container from _loc if I needed it.

import clr
clr.AddReferenceToFile("MyServiceLocator.dll")

import mylib
from MyServiceLocator import *

_loc = MyServiceLocator.GetInstance()
GetInstance = _loc.GetInstance

## Go ahead and load up some of the common services
mymgr1 = _loc.GetInstance[mylib.srvdef.IMyManager1]()
mymgr2 = _loc.GetInstance[mylib.srvdef.IMyManager2]()
mymgr3 = _loc.GetInstance[mylib.srvdef.IMyManager3]()
mywebsrv1 = _loc.GetInstance[mylib.srvdef.Web.IMyWebService1]()

As you can see, accessing a generic is as simple as using [Type] instead of <Type> like you would in C#. I chose to setup mylib as a seperate module that could load up all of the core libraries from our code base that I use on a regular basis. This is a really simple module that I use to namespace things in a more shorthand / “python-y” way. I may at some point turn this into a Python Package to make the namespacing a little clearer. Most of the time (because I use the locator) only need the definition library so it would be nice to be able to only import that.

import clr
clr.AddReferenceToFile("MyServices.dll")
clr.AddReferenceToFile("MyWebServiceGateway.dll")
clr.AddReferenceToFile("MyServiceDef.dll")

import MyServiceDef as srvdef
import MyServices as srvs
import MyWebServiceGateway as websrvs

Read the rest of this entry »

Tags: , , , , ,

Python and socket programming: a quick chat server/client

Posted: February 8th, 2011 | Filed under: Programming, Python
Author:
No Comments →

For some reason tonight I thought, I don’t know enough about lower level networking or threading. What better way to make it all happen than with Python? So I started looking over the Python docs for the socket module and the recommended BSD socket lib documentation. At the bottom of the page the Python docs have a basic server-client setup to test out the basic functionality.

I worked over that and found it easy enough but wanted more. Then I wanted more after that… Once I got a bit of a handle on what was actually happening with the socket.accept() method and send() and recv(). I had a much better idea of what needed to be done and I set off to write my own little server module. I quickly found that to be just not quite enough, so I wrote up a quick Server class and an accompanying ChatClient.

I was pretty happy how easily I could just offload to a thread. In a few places I got a little ambitious about how I implemented things, the truth is, I don’t suspect it would be that hard for me to expand what I’m doing and I could have server commands and chat alias’ etc. The thing is that I’m amazed and thrilled that I was able to go from effectively no knowledge of socket programming at all to a little knowledge and a mini socket communication server in just a couple of hours. Python is pretty awesome. I almost wish I had a purpose for this idea, but I just don’t really need it.

Read the rest of this entry »

Tags: , , , ,

Copying files in IronPython

Posted: February 7th, 2011 | Filed under: Programming, Python
Author:
No Comments →

I’ve been talking a lot about IronPython and Python. So this is just continuing the theme there. A little more about a script I wrote today. Because of the way I’m using things, I needed to be able to copy a big collection of assemblies from one my project folders. I’m sharing this just to show simple it was to write. I added it to my new utils module.

import os
import shutil
from System.IO import Directory

## wrapper to clear screen
clear = lambda: os.system('cls')
## wrapper to know the current directory
curdir = lambda: Directory.GetCurrentDirectory()

## update - turns out I don't need the .NET API for the current directory
## this does the job
os.getcwd()


FROM_PATH = '..\\....\\bin'
DEST_PATH = curdir()

def copylatest(dest = DEST_PATH, from_path=FROM_PATH):
    for s, d, files in os.walk(from_path):
        for f in files:
            shutil.copy(from_path + '\\' + f, dest)

I added that wrapper for the CurrentDirectory because the built-in os function wasn’t working for me in the IronPython console, and the clear screen wrapper was nice too. Essentially 3 lines of code to find all the files and copy them out and yet, I have a feeling there is an even more concise way to do this.

Tags: , , ,

Extending my IronPython ToolSet: Truth Values

Posted: February 7th, 2011 | Filed under: IronPython, Programming, Python
Author:
No Comments →

If you haven’t seen what I’ve already done with my config module, then you should probably look over my last couple of posts about IronPython before you read on since I’m kind of building on that existing information/knowledge. My IronPython console config module, How I override the ConfigurationManager for the IronPython console, and to a lesser extent Talking to Google’s Custom Search API.

After reading over my last post about some extensions to the small config module I’d built a friend and coder extraordinaire (Corey Tabaka) raised a couple of points about how truth values in Python are evaluated. Which was nice because it cleaned up a few lines of code and helped me with my next addition to my config module. One of the key things he pointed out was this check I was using a lot in changing and loading my environments:

if _envs == 0:
    ## do stuff

This isn’t wrong (although slightly wordy), but it made it obvious I wasn’t aware of really how Python evaluates for truth. So he pointed me to the Python Docs on truth values. Basically, a collection that’s empty will evaluate to false, as well as a None (null for your .NET peeps) value. That essentially turned all those calls like above into this:

if not _envs: # do stuff

Read the rest of this entry »

Tags: , ,