Posterous theme by Cory Watilo

Filed under: programming

Quick Password Policy Function in PHP

Just a quick password policy function in php. Didn't want to have to dig around to figure out how to do it again, so I'm just posting it here

/* * * * * * * * * * * * * * * * * * * * * * * * *
Password Policy requires -- at least 8 characters -- at least 1 lower case -- at least 1 upper case -- at least 1 digit
* * * * * * * * * * * * * * * * * * * * * * * * * /
function pwdPolicy($pwd){
   $policy = "/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/";
   if(preg_match($policy, $pwd, $matches)){
      return true;
   } else return false;
}

myPyTunes v0.2

I've updated and posted the myPyTunes script on Assembla using its Wiki/Trac/SVN project capabilities. I could put it on Google Code, but I figure I try Assembla out since somebody else recommended this to me before. Assembla maybe a bit of fluff, but I'll give it a whirl for now. myPyTunes has been recoded and I'm planning to classify (OOP) it for the next update. Another step will be to make it a fully integrated web application with server so it's completely portable. In due time I guess, but until then, here is the link to the Main Website and SVN http://www.assembla.com/wiki/show/mypytunes 

myPyTunes: iTunes from the Terminal in Python

Inspired by the Controlling iTunes from the Terminal article explaining a bash shell command line script to (as the title says) control iTunes from the terminal. I liked this, but I felt I needed a bit more flexibility (meaning I want it coded in something i know better), and I really like Python (especially when i decide to class-ify this script), so I decided to port it over to Python.

I found this useful to have installed on the Mac Mini sitting on a desk while i was across the room on my Powerbook. Very handy since I didn't want to have to get up every time I wanted to change the song, or pause it when the phone rang, etc. So far its a pretty clean traslation over with a few modified functions, and a few functions I've thrown in from other posts I had seen, or functions I feel would be cool to be added.

I've only tested this on OSX 10.4.11 - iTunes 7.6, so even though I believe it should work on other versions of iTunes/OSX, don't take my word for it, but please let me know if you do run into any problems with it. Right now i'll upload the file along with this blog, but i'll be sure to use a versioning tool as i make updates.

Download myPyTunes here - Right click the link and choose "Save As.."

Here is the basic help menu when you type in "itunes -h":

----------------------------------------------------------
iTunes Command Line Interface 
----------------------------------------------------------
Usage: /usr/bin/itunes <option>
Options:
status = Shows iTunes' status,
current artist, and track.
play = Start playing iTunes.
stop = Stop iTunes
pause = Pause iTunes.
playpause = Play/Pause iTunes.
next = Go to the next track.
prev = Go to the previous track.
mute = Mute iTunes' volume.
unmute = Unmute iTunes' volume.
vol up = Increase iTunes' volume by 10%
vol down = Increase iTunes' volume by 10%
vol # = Set iTunes' volume to # [0-100]
quit = Quit iTunes launch = Launch iTunes
playlist @ = Play iTunes' playlist named @"
list = list playlists.
shuf = turn on shuffle playlist
noshuf = turn off shuffle playlist
ostream = open stream
help = what's showing now
----------------------------------------------------------

Python: where is the switch/case?

i was writing up some code in python and had several if/else like statements that i figured would require a better syntax and figured that the switch/case method would possibly be a better way to handle it. lo and behold, after research...there's no switch/case like statement!! i found several ways of solving the issue, which seem to be rather interesting.

many people thought that the if/else was probably the best way to go...of course we can't have that, and continued to find some people stating to use the dict like command to determine your call. for example:

def performAction1():
   print "some crap"
def performAction2():
   print "some more crap"

   "action1": performAction1, 
   "action2": performAction2, 
   ...etc... 
}[actionToPerformString]()

this seemed to be a good way to do it, but something about the actionToPerformString trailing like that bothered me, so there was also this method which seemed to be more visually pleasing to me:

def defaultActionToPerform():
   print "default crap"
action = {
   "action1": performAction1,
   "action2": performAction2,
   ...etc...
}
action.get(actionToPerformString, defaultActionToPerform)()

as you can see, it also allowed for a default function to be called, plus it reall just does look cleaner. if anybody has a more elegant solution, please feel free to comment.

the Jadecell Javascript toolkit

so in my spare time i've been sitting in on the mootools (a javascript library) IRC room...and have been in on a bit of conversations here and there. There are several times where i'm just oblivious to alot of what they're talking about...mostly because this group has advanced so far into the development of the project, its a bit hard to catch up for a noob. i'm sure some can, but i havent been so lucky, i think mostly because i'm just not familiar with javascript completely anyway. i've dabbled alot and restructured js code to work the way i want...but that doesn't mean i know javascript. So i've decided to do my own toolkit, framework, library or whatever you want to call it. I'm in no way trying to compete with other toolkits, so please don't bash on what i'm doing...although constructive criticism is always welcome. This is totally for learning purposes, and i'm just making it available to anybody else who could find it useful. It's still a work in progress, and all i've got so far is a set of tools for divElements, ie innerHTML, border, background, etc. grab the source using svn:
svn co http://dev.jadecell.org/jadecellScript
or directly here This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
Media_httpicreativeco_wudar

A javascript pulldown "move module" by value or text

This is a tough one to create a subject for, but here are the details:
Move by Value <--move | move--> Move by Text <--move | move-->
On the web application I develop on, there was a previous moveModule created and used that would grab the selection from a pulldown and move it over to another pulldown (this was used for dynamic adding and selecting if you don't know what you could use this for). The issue was that if you moved a selection from one to the other, and then back, the selection would then NOT be put back in the right place but at the end of the pulldown box (this can be annoying if you have a pulldown list full of states or countries). This made the original function very simple and small since it only needed to add an option at the end, but left several users wondering where the option went especially on a very very long list. The initial remedy was to check the values and then add and insert accordingly. This did the trick, only if the value and text matched. Sometimes the option value was substitued for an id number (useful with a SQL table), so if the id's and text's didn't sync accordingly by number and alphabetical order, then you'd have a mismatch. So I developed two functions that would take the place according to which the programmer defines. One for Value and one for Text (moveModuleByValue & moveModuleByText). In the example html file, if you view the source you'll notice that i've mismatched option 'ad' to accurately see the differences in the two move methods. Try to move that option back and forth between the two move functions to see it work effectively. I would have tried to make this just one function, but i was not able to figure out how to interchange the DOM of .text and .value flawlessly. If I have time to hack at it more i'll figure it out, but this seems to do the job just fine for me. Comments and suggestions are always welcome. movemodule.html movemodule.js