April 25, 2007
mitch @ 2:26 pm on April 25, 2007
I know I haven’t written about much of the code I’ve written over the last couple years or so… as I don’t consider myself a “programmer”. I’m a Systems Administrator by trade but with a flare for scripting where I will write scripts to make my job easier (even so I no longer have to do my “job”). I’ve been learning python over the last year or so, and I think I’m really finally starting to get it and really be able to apply what I’ve learned to new scripts. Anyway, as a means to help me remember this and that maybe it could be helpful to someone else down the road. I’m not sure if there is a better way to do this or if this is the proper way. But what I was looking for was a way to be able to pass a generic name and do a LIKE sql search for it. My example is actually coming from using bacula at work, and I’m trying to get some better reporting and store some statistics(I will eventually post what I come up with…) Anyway, heres a bit of sample code to illustrate what I came up with(I run a postgresql database, but I don’t believe it would be any different for mysql other than the original module).
#!/usr/bin/env python
import sys, psycopg
DSN = "dbname='bacula' user='bacula'"
class pgDB:
def db_connect(self, DSN):
try:
conn = psycopg.connect(DSN)
except StandardError, err:
print "Error: Unable to connec tot the database, exiting...", err
return Exception
else:
return conn
def do_query(self, conn, query, args=[]):
cur = conn.cursor()
try:
cur.execute(query, args)
result = cur.fetchall()
return result
except StandardError, err:
print "Error Executing Query: ", error
def main(clientName):
DB = pgDB()
try:
myDBconn = DB.db_connect(DSN)
except:
sys.exit()
clientName = "%" + clientName + "%"
query = "SELECT * FROM client WHERE name LIKE %s"
result = DB.do_query(myDBconn, query, [clientName])
print result
if __name__ == "__main__":
main("hostname")
Assuming the spacing is all correct, that should work. The key being having to append the %’s to the word we are searching for before it is injected into the predefined query… kinda weird how it does that as i was trying to have the %’s in the query before the clientname was injected having the query look like “LIKE %%s%” which was causing problems… and I suppose I can understand why…
Anyway, as I said, I’m not a programmer by any means, this is just some notes for myself. Maybe they will help someone else too…
Python — No Comments
April 21, 2007
mitch @ 11:55 am on April 21, 2007
Well, I’ve been drooling over motorcycles since I sold my CBR600F3 back in 2002 (or was it 2003?). Which was before I got married, used the money to buy my wifes engagement ring. Anyway, she’s been saying she would let me get another one and well, it was either the motorcycle or a new (to me) car. I went with the motorcycle. Overall it would be cheaper than the cars I was looking at, and I don’t really “dislike” my civic. I still wish I would have bought the Si… but I like it none the less. The suspension mods I’ve done to it make it handle real well I think and I’d hate to have to do that all over again on another car.
Anyway, back to the subject of my post. My 2006 Honda - Tribal Orange - CBR600RR! I drove it home from Tooele yesterday and was a nice ride. Its going to take some getting used to riding again. As well as this bike handles a bit different than my old F3. I borrowed a helmet from my wifes uncle to ride it home with. And my “Pure Orange” helmet was shipped yesterday. I can’t wait till it gets here! I will have pics as soon as I can find a good place to take some of it.
Life — No Comments
April 18, 2007
mitch @ 7:32 pm on April 18, 2007
Seriously, I love the Colbert Report on Comedy Central and when Steven asks to be Google Bombed as The Greatest Living American, that is what he will be.
Funny — No Comments
April 17, 2007
mitch @ 1:03 pm on April 17, 2007
- UPDATED - April 17th 3:41pm - it appears that the shooter did purchase the 9mm through a gun shop. However, I have also found some of the short 1 act plays that the shooter had written. While some may claim that they’re sick and twisted. I would rather argue that they’re are quite immature for the age. The story as its written seems much more junior high to me. Tho, possibly some type of insite into his own persona… Thinking he definitely needed some type of psychiatric care.
As, most of you have undoubtedly heard, there has been an awful tragedy at Virgina Tech, and my heart goes out to the families of the victims.
Those feelings aside… I’m again, infuriated by the responses people have been giving with regard to the situation. Saying that VT “should have locked down the school and notified students of the situation”. Is the scale of this type of claim really that far above and beyond peoples comprehension? The sheer logistics of such a feat are mind boggling. To say that after what appeared to be an isolated incident in the first shooting with no information or evidence leading anyone to believe there would be another shooting 2 hours later, they should have locked down the whole school!?!? And that they should have warned everyone? Again… if this was say Manhattan, I don’t think anyone would be able to walk on city streets… EVER. If they had to follow the same guidelines… A normal High School, is entirely different as its usually very controlled with one large building and maybe a few smaller ones just around the perimeter and usually less than 10 buildings total, and <5,000 students. This was an open College campus with a mix of residential and commercial intermixed to boot. With over 40,000 students alone. Its would be kind of hard to lock down over 700 buildings!
Why is it that when a tragedy strikes… we want to pawn off the responsibility of it onto “things” and “entities” instead of the person/people that committed the acts? I hear the cult of Scientology is saying that the shooter was probably over medicated on anti-depressants, as they had also “discovered” that is what caused Columbine. Yeah… you read that right… Or, VT didn’t do enough to warn people, or they didn’t shut down the campus… This is all BS… honestly. Don’t get me started on Gun control, as it had nothing to do with it.
I’ve seen reports that the serial numbers were filed off of the guns…. why would the shooter, prior to doing what he did, file off the serial numbers to his guns? Quick answer is he wouldn’t.. why bother, he went in knowing he was probably going to die. By his own hand or the police or someone else with a gun, I’m pretty sure he knew he wouldn’t come out of it alive(Also, none of the other tragedies have ever had filed off serial numbers). So again, why were these ones filed off? The simple answer was that is the way they were when he got them. Which also means he did not obtain them legally. So more strict gun laws WOULD NOT HAVE PREVENTED THIS FROM HAPPENING. Its been said many times, but I still think it needs repeating: The only thing stricter gun laws do, is prevent lawful citizens from obtaining guns. Making guns illegal will mean only criminals will have guns. If anything, we should be encouraging more lawful citizens to carry guns.
Which leads to the latest whipping boy… Video Games. Jack Thompson was very quick to exploit this tragedy for his own agenda against the Video Game Industry. My argument is the same as I’ve written about before. Look at the statistics… Look at the TENS of MILLIONS of gamers in the US alone. Then look at the numbers of these types of incidents(I’m not trying to discount them, just trying to bring a little perspective with regards to gamers)…. If Video Games were training our youth and even those that have aged into their mid 30’s now… we are looking at MUCH less than 1% of possible gamers.
I don’t buy it, any of it. Why the media allow the lunatics to spread their own propaganda without ANY evidence what-so-ever is beyond me. As bad as that is… People believe it… I don’t know which is worse… more and more, The movie Idiocracy becomes more and more ironic… Which seems to be leading us more towards that of V for Vendetta. The police state everyone seems to think is a great idea, in order to feel “safe”.
I believe it was Ben Franklin (on of our founding fathers) that said:
He that would give up liberty for a little temporary safety, deserves neither.
Life — No Comments
April 12, 2007
mitch @ 1:55 pm on April 12, 2007
I’ve been in and out of smaller tech like schools since graduating from High School back in 2000. The reason for my preference towards them is that I’m not interested in a lot of BS. Why is it that employers only want people with degree’s? I can understand that some fields of study definitely require formal education and I wouldn’t want a Doctor or Surgeon with only a year or two under their belt studying basic anatomy. I don’t buy that jobs are more technical now than they were 30 years ago. Yes they use more technology now, but technology is usually adopted as the populace adjusts and becomes comfortable with it. I’m not against Education in general, in fact I love learning new things, and wish I could just take classes on various topics all the time. However, I fear the reason is a result of how the Baby Boomers view todays next generation(which I am apart of).
Doing any type of comparing our school systems to that of any other country’s, I don’t believe is really sinking in. I would like to argue that the biggest reason for needing even more education after High School is because of the lack of actual learning happening before and during High School. From my understanding, the problems with the public school system is more a result of society, and the lack of importance put on education. This results in a huge lack of caring for the children going through school. Making the teachers in public education, have to balance between being a baby sitter and education at the same time. My experiences through High School were…. uneventful. I dreaded every day, as I knew that most of the work being given to me, was not really for educating me about a subject, but merely a pacifier. Some of the subjects I was really interested in, but it always bothered me how fast the teachers moved through the chapters. My disdain was compounded by the constant battery of tests and quizzes that distracted me from actually learning the subject, and forced a mindset of just remembering the information long enough to take them. One of my favorite classes, and one I actually remember, was my 8th grade History class. With a teacher that actually made history come alive. His teaching style usually involved him telling stories about the American Revolution and other American History like they happened to a friend of his, or like it was his own story. It made what was written in the book much more interesting, and easier to remember.
What would have made school more likely to mean more, would be real world examples and experience. Apprenticeships come to mind. What ever happened to those? An apprenticeship with a PC builder, or small business, or even lost of guest speakers and tours of larger businesses with information on how their IT infrastructure is done. And after those trips, discussing in class making sure everyone understood the technologies in use by the places that were visited. Those first 12 years of school and especially High School is supposed to help prepare people for LIFE not push them to need more Education for life and career. Its supposed to be the introduction for the basics of life, how to earn money, balance a checkbook (tho, checkbooks should be obsolete in a few years), paying taxes, etc… Explaining the theory of relativity and pondering the purposes for life are not something fit for someone in High School(as it goes well beyond their world view at that time). I would even make the argument that anything past algebra 1 need not be required in high schools… still offer the more advanced courses, but not require them. And by all means, as part of the generals for colleges across the country, start with algebra 1 or 2. I think that exposing teenagers to this broad range of information as a way of making them well grounded try to help them figure out what life is about is the wrong way to approach the situation. Help them understand life, by bringing them into it and making them apart of it.
As a summary, what I’m trying to relay is that today, graduating from High School means little more than being a checkpoint before moving on to college. As such, there is little motivation to learn anything while in High School. Which is only adding to the baby sitter appearance. These are just my observations however, since I have not done much research to backup my points. But I do believe that kids would do better if High School was more focused on life rather than theory and arithmetic. That should be left to the colleges, where the subjects could be given a more just and in-depth look.
School — No Comments
April 9, 2007
mitch @ 4:40 pm on April 9, 2007
Is it me or aren’t there any decent open source time tacking/billing/invoicing? I’m looking for something with a client side GUI, don’t think I’d really care about what kind of database back-end it has…. I’d just like a desktop app that can track projects and time spent on it. With an option for reporting and invoicing. I’ve been using GnoTime and I find it lacking. Its interface is unintuitive, and reporting features are somewhat lacking for what I want to do. I’ve been trying to figure out how to customize some reports for it. What I want is to be able to select a main project, and show total of whats been billed, whats paid, whats waiting to be paid ect… But be able to make that go narrower, down to a specific task if needed and still show the same things. GnoTime can do this, except for the reporting doesn’t seem to work right. And as I said, the reporting is lacking. If I could find an easy way to create the GUI, I’d start working on all the backend stuff to create such a thing, but I find the free GTK+ Design tools kind of odd… I’m not a GUI designer in any sense of the word, so it could most definitely be me. But I’ve had to design some fairly ugly VB apps in the past and those were easy enough to create…. Wondering why there isn’t something comporable for GTK+? I don’t really want to do it in QT mostly because I use Gnome as my desktop and I want it to follow whatever theme I happen to be running at the time. Anyway, I my just happen to write one(in python), one of these days if I can find a suitable GUI builder.
Technology — No Comments
mitch @ 4:28 pm on April 9, 2007
Well, Debian finally released version 4.0! Its been a long time coming, yet again, and I think I’ll be staying with Debian on my server as a result. Since it comes with all of the things I wanted and had been running from Testing prior to its release. I updated to Etch earlier today, so if you experienced problems earlier. Thats what was going on. There was a change with Apache (upgraded to 2.2) That required some changes to my virtual host config file for metauser.net, after I got that sorted out everything else so far has seemed like its working really well… Other than some botched problems with wordpress and a bad plugin (I updated to the latest wordpress finally a while ago too…) But I’m trying to find a decent plugin that will allow me to embed youtube video’s like the one I linked to a while a go(why they can’t include the one thats been put into the online wordpress.com I don’t understand). Anyway, its broken my categories stuff, so thats why this post and the one prior don’t have any listed… its borken and I haven’t been able to fix them yet. Rest assured that once I find the time to fix them I will… maybe later tonight in my other class, since I’ll have SSH access there….
Debian· Linux — No Comments
April 3, 2007
mitch @ 9:33 am on April 3, 2007
My brother came home last week from his LDS mission in South Africa, and he would continually remark that we(being people living in the US) don’t know how well we have it. Which to some degree I agree with him. However, not everyone in this country would agree. I’m not trying to downplay the situations that people live in in South Africa, or any other 3rd world country for that matter. I’m sure its not something I would like to live with either, and I am grateful for the thing with which I am privileged to. This however does not mean I should just take what I have and be “happy”. Wanting more, wanting things to be better is a very worthwhile cause. My brother had made the claim that I shouldn’t be so hard and critical of our government and our current leadership, because I don’t have to put bars on my windows and worry about someone shooting through my windows. I *very* much disagree. As I said, yes I understand that South Africa, in most parts, is very much a 3rd world country, and here I am “living the dream” in the U.S. of A.. The current self proclaimed leader in this world of ours. Heres where I’m comming from, comparing the US, to South Africa is like comparing apples and oranges, they are NOT the same thing. Because of the history surrounding each country and the forms of government in place and the like… the two countries are *VERY* different. In order to make any kind of fair comparisons, you need to look at countries where there are more things that are alike than are different. The so called “1st world countries”. This is how they gain these labels in the first place. And when ranking 1st world countries, guess where the US falls, in all the areas that should matter? Dead LAST. Sure, we still top the charts in military power and expertise, but this is also coming into question and China is the up and coming star in this arena. But we are still the only 1st world nation that does not give Health Care to every citizen of this country. Our public education system is failing miserably and lieing about it to cover up this fact. And something I’m more inclined to follow, we are also falling way behind in Broadband connections for our citizens as well. America isn’t much for being the land of the free like it used to be. No instead we want to keep people from entering this country, we want to hold people indefinitely and without charging them with any crime, and then torture them so we can charge them with a crime. We want to award multi-billion dollar government contracts to companies that our Vice President has a stock in. We want to have wiretaps and listen in on phone calls without warrants. All of this is *against our constitution*. The foundation of this country! And the american people just blindly accept this, because we feel we need protection… from what? Yes, 9/11 was a tragedy. It resulted from what I can tell, was our leadership asleep at the helm. Now, they’re asking us to give up our freedoms that this country was founded on, for some pseudo safety. Our elected officials are running away with billions and our freedoms, and all the American people seem to care about is who’s the real father of Anna Nicole’s baby! *WTF!*
Legal· Life· News· Politics· Thoughts — No Comments