Flattery…ain’t always that flattering.

So I can now say that the idea of flattery is not all its cracked up to be, at work I develop some tools that the department uses and to help out my boss and an ‘assistant’ sometimes ‘help’ out. Today that helping ended up being bastardizing code I had previously written that worked just fine.  There were lines commented out all over the place, loops within loops (with additional code that wasn’t there before) that just made the whole thing shit the bed when it came time to actually look at what was being created with the code.  Turns out they don’t know how to properly format HTML or even how to design something to be efficient; instead of just pulling data for the currently logged in user they created this huge drop-down menu that lists all the users and you pick your name out of that list.

Normally I wouldn’t even bother complaining about this here but the supervisor who so graciously left their name in comments they put into the code claims to have been a programmer at their previous job, however more and more I think they were simply writing SQL queries and using some kind of a front-end tool to format and display everything.  Sure that still indicates some level of skill in knowing how to do joins and all the other fancy wizardry associated with databases but it doesn’t indicate any kind of a knowledge about actual programming in general (like not putting things inside loops if it doesn’t need to be there) or even simple things like how to properly utilize html tags to positive effect.

Simple integrity script

So I came into work today and my inbox had a wonderful little gift; a co-worker had made changes to some of my code that was considered production without providing me a log of what changes he made, just a general not of what sub-folder might contain changes that were naturally NOT included in the git repository.  Naturally I was so pissed about this that I considered doing bodily harm to inanimate objects while screaming profanity, then I got busy actually finding all the things he changed.  All I had to work from was the bash history showing me every file he touched, so I manually diff’ed them against files from the repo that I knew he hadn’t touched only to find out he did more looking than touching, but that was probably a godsend really once I realized he was changing commented out code (hope he didn’t expect to see anything actually change).

After I got all the non-changes found and replicated in the repo by hand (obviously hes not up to speed with such things as version control) I decided I was done fucking around with undocumented changes to live production code which could have all kinds of nasty consequences, thus the following quick and dirty script was created.

# integrity.sh
# author: dword
# purpose: generate daily md5 sums of files and email them off for tracking of changes

# Lets generate the msg file, not used currently but will be later

echo "*** Daily Integrity Report ***" > int.msg
echo " " >> int.msg
echo "Generated: " >> int.msg; date >> int.msg

# Now to tag the log with today's date

date > int.log

# Generate MD5 sums for every file we want to track

for f in $(find /var/www/html/); do md5sum $f >> int.log; done

# Mail it off!

mail -s "Daily Integrity.sh Report" paranoid@somewhere.tld < int.log

# Clean up files

rm int.log

Just change the path that find uses to whatever location you would like to keep track of and make the email actually something that works, slap it in a @daily crontab and you should be golden.  Its not anything fancy like tripwire or the like but at least hopefully it will save someone else from having to do a bunch of manual work diffing files wondering which were edited and which were just looked at.  I would have liked to simply lock the reject out who managed to cause this whole mess in the first place but I don’t think the boss would appreciate me circumventing the chain of command to start decreeing who works on what, even if they are total morons who probably shouldn’t be allowed to touch production systems in the first place.

Powerball number picker

So I spent a little time the other day applying what little I know of Python to the concept of picking Powerball lottery numbers because I had nothing much else to do that the time.  In the interest of not only content put putting more of my terrible code out there for people to laugh at I present my simple powerball picker script.

from array import *
from random import *
num = array('i')

def create_array():

        for i in range(0,59):
                ins = i + 1
                num.insert(i, ins)
        return num
def pick_a_number():
        your_number = ''
        for n in range(1,6):
                ca = create_array()
                pick = randrange(0,len(ca))
                your_number += str(ca[pick])
                your_number += '  '
                # now we exclude the number
        print "Your Picks >> "+your_number+" Powerball: "+str(randrange(1,36))

start = 1;
stop = int(raw_input("How many picks would you like to generate? "))

for p in range(start, stop+1):

* note – if you win a huge jackpot with numbers from this send a few bills my way!

Account Info Script

Had to do a quick crontab job at work to grab user details out of /etc/passwd and email the details in a report, here is the resulting script

> account-report.txt
date > account-report.txt
echo -e "=== Account Report ===n" >> account-report.txt
hName=( $(awk '{print $1}' $Nlist) );
for name in "${hName[@]}"; do

        users=$(cat <<EOL
                cat /etc/passwd | grep "/bin/bash" | grep "[1-9][0-9][0-9]" | cut -d: --fields=1,5

        echo "Host: $name" >> account-report.txt
        ssh -o StrictHostKeyChecking=no ${name} "$users" >> account-report.txt
        echo -e "End of $name accountsnn" >> account-report.txt

mailx -s "Monthly Account Report" user@host.tld < account-report.txt

It grabs a list of hostnames from nodelist.txt and utilizes a ssh key-trust to connect to the hosts without supplying a password.  We lucked out bigtime that there was a trust already setup otherwise the whole process would have been overly complicated requesting permission to setup a trust in the first place.

Achievements to be unlocked?

So at work we have to set a batch of goals ever year that we work towards achieving, however this year it seems they are actually going to make us do this.  We have to accomplish these goals under penalty of losing our bonuses.  Two of my goals are going to drive me nuts, the fist being that I must complete the Portal project where I have to develop a set of internal tools.  We are going soft launch by the beginning of March so I’m under retarded levels of pressure to produce working code at an astronomical rate.

Then comes the part where they financially knee-cap me and make my brain implode all at once; I have to take and pass my RHCSA before the end of the year.  What makes this a pain in the ass is that the company wont pay a single cent towards this since they don’t pay for certs, only coursework done at accredited colleges (see also: CCNA).  Last I priced them a single sitting for the RHCSA is 400$ and its a multiple hour long test (that I will probably have to burn personal time to take in the first place).  To make this even more fun I have to study for this in-between doing my normal duties and coding half of a fairly complex project in which there is no set-in-stone list of features to work on, just a starting list that is subject to change from one week to the next.

To make the turd sandwich slide down just a little bit easier they are trying to wash it down with a 6% raise, but I would almost prefer being given more hours in each day so I have room for code, normal work, studying and still be able to get a decent nights rest, but sadly common sense at work aint that common.

Youtube Ripping Made Easy

12-11-2014 – Updated bash script syntax to reflect usage of –youtube-skip-dash-manifest to keep errors down when doing bulk processed lists of videos.

There are plenty of annoying windows tools that claim to be able to properly rip audio from Youtube, however I don’t trust most of them any further than I can throw a car.  Here is a dirt simple guide to ripping audio on Linux, you could even accomplish it on a headless server if you really felt like it.

The center piece of this process is youtube-dl which is just a python script which takes care of all the work of pulling down and converting the files to mp3.  Go ahead and pull down the script, and drop it somewhere that you can access (check your $PATH variable depending on your distro of choice) and don’t forget to chmod +x the file so that its executable without first invoking the Python interpreter.  At this point you also want to make sure you have ffmpeg installed as that’s what does all the leg work for youtube-dl.  Once you have that out of the way lets look at a sample use of this program to figure out how to streamline things so you don’t have to type out a pile of arguments every time you want to pull down a file.

youtube-dl http://www.youtube.com/whatevervideo -l --prefer-free-formats --extract-audio --audio-format mp3

Fortunately the developers of this app didn’t go ape with cryptic command line arguments, pretty much everything there is self explanatory except for -l, which to save everyone the time of checking the –help output is to give it a litteral file name instead of the pseudo-random one that it derives from the youtube id string.  Now to simplify things even more, lets make a bash script called ‘ytdl’ in the same location you placed youtube-dl earlier.


/usr/local/bin/youtube-dl $1 --youtube-skip-dash-manifest -q -o %(title)s.%(ext)s --prefer-free-formats --extract-audio --audio-format mp3

Make the script executable and now all you have to do is invoke ytdl <youtubeurl> and it will kick off the process.  Background the process for bulk conversions or better yet if you really want to make things slick create a php front end for the whole thing (but make sure to password protect it) so you can pull down mp3s from youtube.  The one caveat is some videos don’t convert over to mp3 but mp4 or other strange formats that won’t work with this, at this point I don’t have a real fix for this but I’m sure one is in the works somewhere.

New Project Time

So I finally decided to start a complete re-write of the code that drives The Bushwick Dream from scratch.  Not a single piece of existing code is going into the new site in hopes of cutting down on some of the fat that its developed over the course of two years.  Upon looking through the code I’ve realized that there were whole classes floating around for managing podcasts, source code and various other things that were used when I originally started Pure Defect.  A quick check shows that the site has grown to a whopping 7,063 lines of code over the course of its lifespan, and some of that definitely needs to go.

The re-write also lets me address issues with the site that have been long-standing but would take far too much effort to fix in the current code without potentially breaking everything else in the process, such as the outdated and archaic template engine that accounts for roughly 1400 lines of code across two different files.  The WYSIWYG used for editing content is also a kludged together mess that seems to break just about everything it touches unless handled with kid gloves, with the re-write its going away in favor of a much more unified system with a proper media management component.

Last and hardly least are the new features like modular plugins allowing for new features to be integrated into the site without breaking existing features.  Currently two monolithic files do about 80% of the work for the site, but with the new design everything will be broken out into separate files based on the role of the code allowing for a much cleaner back end when I have to make changes.  This approach also means I won’t have to rip my hair out of my head when a certain someone asks for a new and exciting feature because it will be a matter of dropping the plugin file into a folder, adding a few quick tweaks to the template and then going back to watching Netflix or staring into the abyss that is reddit.

Its probably going to be a long process to do properly, but in the end not only will this make my life much easier from an administration standpoint but it will also allow me to use the code base in the future to deploy other sites much faster and improve my coding chops by forcing myself to learn new methods and styles.

Site Re-Design and Launch Complete!

Well after months and months of work I finally launched a brand new Bushwick Dream site this afternoon.  Its been a long time coming since the site first started and I’m glad its finally over with so that I can go back into maintenance mode, but damn was it a fun run to make the new features work and iron out all the bugs.  For anybody interested you can visit the new and improved site here.

A calendar in less than 50 lines of php

It ain’t pretty by a long stretch, but the fact that it can fit into less than 50 lines of code and could be easily converted to a function for use in existing projects makes me a very happy camper, hopefully it will make it into the TheBushwickDream in the near future.

$month = $_GET['month'];
$days =  cal_days_in_month(CAL_GREGORIAN, $month,'2011'); // num of days in month

$ts = mktime(0,0,1,$month,1,2011);
$month_name = date('F',$ts);
$first_day = date('w',$ts); // numeric for the first day in the month

// 0 = Sunday, 6 = Saturday, layout is Sunday to Saturday

$d = 1;
print "<h3>$month_name</h3>";
print "first day is $first_day, $days in month!<br />";
print "Su, Mo, Tu, Wd, Th, Fr, Sa<br />";
print '<table width="50%" height="50%" cellpadding="50%" border="1">

for($week = 1; $week <= 5; $week++){
	print '<tr>';
	if($week == 1){
		for($day = 0; $day <= 6; $day++){
			if($day >= $first_day){
				print '<td>'.$d.'</td>';
			} else {
				print "<td> </td>";
	} else {
		for($day = 0; $day <= 6; $day++){
			if($d <= $days){
				print '<td>'.$d.'</td>';
			} else {
				print "<td> </td>";
	} print '</tr>';
print '</table>';

Bored Code: Primes in Perl

Yet another boring day at the office, so I decided to dust off my Perl book and try to relearn some basic chops in the language and maybe find a good use for it.  Unfortunately that was not the case and in the process of getting myself familiar with it I ported some old code I wrote for artificially creating a load on my servers by crunching prime numbers.  Its a pretty ghetto piece of code and I’m not sure about its limitations so if it causes your machine to catch fire or start making noises like a dying goat I’m not responsible, actual bad code after the break.

Read more

Close Bitnami banner