• Saving files with Duplicate Filenames

    If I want to save a file, but make sure to not overwrite files, and instead append a number to the end of the file name using Python I may want to write something like this:

    #in this case I want to take a title and use it as a filename
    filename = title
    counter = 1
    while os.path.isfile(filename):
        filename = title + " " + str(counter)
        counter = counter + 1
    # write a file using the filename variable as a filename
  • Script works but not via Cron

    I spent more time sorting out a problem than I should have today. I was trying run some scripts from a cron job, they weren't running. They ran fine when run outside of cron, that is, they ran fine on their own or when I manually ran them, but the moment I tried to run them from cron they didn't work. My precise situation was a bash script that was calling some python scripts and some relative path references in the python scripts were breaking. I eventually realized that files were being created in my home directory that were supposed to be created in the directory containing the python scripts. The problem was that the directory that cron runs out of is different from where I was running it manually. That is, if I had ran "pwd" I would have not received the result I expected.

    The fix was to "cd" into the the directory I wanted to run the scripts from at the beginning of my bash script. The result was something like this.

    cd /home/tory/myScript/
    python firstScript.py
    python secondScript.py
  • List all URLs to YouTube user's videos

    Here is a python script which will list all the URLs associated with a YouTube user's videos

    # this outputs all the video URLs for a particular YouTube user
    from urllib.request import urlopen
    import xml.etree.ElementTree as etree
    ytUserName = "7sagelsat"
    next = "https://gdata.youtube.com/feeds/api/users/%s/uploads" % ytUserName
    while next:
        xml = urlopen(next)
        tree = etree.parse(xml)
        root = tree.getroot()
        # get all the links on the xml page
        for i in root.findall('{http://www.w3.org/2005/Atom}entry'):
            print (i.find('{http://www.w3.org/2005/Atom}link[@rel="alternate"]').attrib['href'][:-22])
            # find the next xml page if available
            next = root.find('{http://www.w3.org/2005/Atom}link[@rel="next"]').attrib['href']
            # we are at the end
            next = ""
    print ("\nfinished")
  • Small tip

    Something to remember, if a service isn't working right, check to see how much disk space is left, if it is zero, then that could be the cause of the issue.

  • Hide Facebook Posts based on Content in Chrome

    This Tampermonkey script allows you to hide Facebook posts based on their content.

    // ==UserScript==
    // @name         Facebook Sanity
    // @description  hide facebook posts containing sepecific words / phrases
    // @match        *facebook.com*
    // @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
    // ==/UserScript==
    document.body.addEventListener('DOMNodeInserted', function(event) {
    }, false);
    // The reason for using a function like this is to call this script again
    // during subsequent AJAX requests by Facebook
    function myContainer() {
        // if adding or removing, follow the format below, some characters need
        // to be preceded by backslashes, definitely ellipses
        var myList=["Occupy Monsanto","Im here to offend \(18+\)",
                     "StreetArt in Germany", "Fascinating Places",
                     "Illuminati Exposed Media", "The Peoples Boycott"];
        for (var i = 0; i < myList.length; i++) {
            // entirely remove the post
            //$("li:contains("+myList[i]+")").css("display", "none");
            // replace the post with text saying that it was deleted

    Update: This does seem to result in a performance hit.

  • Ubuntu Firewire Audio Kino

    I was capturing some digital video through firewire on Ubuntu 12.04 with Kino and there was no sound. Starting Kino with this comman remmedied the situation.

    padsp kino

    The error I was receiving was this:

    ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM /dev/dsp
    Could not open ALSA device "/dev/dsp": No such file or directory
  • Libreoffice Grammar and Spelling Checker

    I had some problems with the Libreoffice spellchecker and grammar checker in Writer today. I tried to install the LanguageTool extension but it was giving me permission issues that I wasn't able to quickly fix. I had upgraded from an earlier version of Libreoffice today and I read that the old user profile might be causing an issue so I also removed ~/.config/libreoffice to no avail. I then removed and purged libreoffice-* and reinstalled. I was then able to install the language tool, as well as the hunspell-en-ca (Canadian English) Ubuntu package. As of this evening, I have a very nice Libreoffice installation, complete with grammar and spell checking! On a side note, I do recognize that this was more troublesome than it should have been, spell checking and grammar checking should be pretty standard, and something that every user makes use of, including those less tolerant than me. But, what can I say? Beggars can't be choosers, it's libre and gratis. Lastly, afterthedeadline.com is a language tool I use for this blog, and it works pretty well. It can also be used with Libreoffice but I am hesitant to do so. It is a cloud service that checks your language use, and since unlike my blog, usually the content I produce in Libreoffice is private it constitutes a privacy/security threat. It is possible to run your own After the Deadline server but that is a fair amount of effort for spelling and grammar and in addition it takes up a fair amount of system resources.

    Update: Strangely, a friend just asked me about this, a few days after I had this problem. I supplied him with some instructions that I think would be useful for people who might end up here. The following should probably get you a good Libreoffice install. I haven't tested them, but they should be pretty close. There are some unnecessary commands here, but, I'm just sort of choosing the nuclear option to kill an ant.

     apt-get remove libreoffice-*
    apt-get purge libreoffice-*
    rm ~/.config/libreoffice/ -r
    add-apt-repository ppa:libreoffice/libreoffice-prereleases
    apt-get update
    apt-get dist-upgrade
    apt-get install libreoffice
    apt-get install hunspell-en-ca

    Then install this plugin http://extensions.libreoffice.org/extension-center/languagetool and restart Libreoffice. Update: In Ubuntu 13.04 with Libreoffice and Language Tool 2.1 I needed to install libreoffice-java-common in order to install Language Tool.

  • Recursive Chown with Exceptions

    I needed to apply a recursive chown command to my home directory today. The problem is that I have a very large external file system that is mounted in my home directory, one that must remain mounted. I did not want the chown to be applied to the remote file system and chown doesn't have functionality built into it to perform advanced recursive actions, like, recursive except with x. Then I remembered the -exec switch on the find command and realized that -exec is a great way to get recursive functionality for any command that your want to run with advanced recursive functionality. In my case, I used the -mount switch to limit the execution to the local filesystem only, but other regular expression conditions, or other filtering mechanisms could be used too! This is an important and flexible lesson. It's really quite obvious in hindsight, and probably obvious to a Linux sysadmin guru, but in any event, here it is.

    find * -mount -exec chown tory:tory {} ;\
  • Website Specific Browser Windows

    In continuation of the troubles I had in my last post, I finally found a stable way to create a web app window in Ubuntu, and the solution was available all this time, I just didn't know it. In Chrome there is built in functionality for application shortcuts as seen here that accomplishes everything that I wanted. With one caveat however, it does a poor job at choosing an icon leading to a pixelated mess. In order to fix the icon issue, I had to create a custom launcher of sorts which complicated the matter. For this particular issue I decided to make a video: I know the goals of the built in functionality heading for Ubuntu 12.10 and the goals of Fogger are to have even greater desktop integration than what this offers, but this already has two major benefits for me. One being the increased screen real estate that occurs because of the removal of the address bar and the tabs, the result is even better than Chrome without the system title bar option enabled. But even more important, workflow is substantially improved because instead of navigating through mounds of browser tabs I can use the navigation tools which are built into Ubuntu, such as being able to ALT+Tab, or being to use the Compiz expose, or any of the other window switchers. Certainly there is limited tab navigation capabilities built into Chrome but none is as superior to the OS navigation. The OS navigation is superior because from the OS switching tools I can always immediately switch to my desired destination without other steps. Consider these two examples. One is where there is no web application functionality, I might ALT+Tab to my browser window, then I would have to perform a second operation to get to the desired tab if I have not by luck landed on it. The second situation is where the web application functionality exists, in this scenario I can ALT+Tab immediately to where I am trying to go without the need to select a tab after activating the web browser. And to me, this is an enormous benefit.

  • Facebook Wall JavaScript Delete Bot

    This will be very quick, I cannot dedicat much time to this sort of thing at the moment, I have already spent too much time on it. But, as I have shown before I have interest in being able to delete old Facebook wall posts. This is because conversations we have in person are largely ephemeral and I think Facebook should be too, or at least have the ability to be.

    I have discovered a new technique to do this, different from my previous shaky attempt this one works very well. This time I have created a JavaScript bot that uses some JQuery that runs in a FireQuery console which is a modification of a popular Firefox extension named FireBug. When doing this, one must remember to click "JQuerif"y so that the script I have written has access to the JQuery library.

    To show where the script goes I have include the image below (but of course you'd be on Facebook):

    This script is to be run when you are on the Facebook "activity log" page. Within that page you could select, for example, "All," "Your Posts," "Post by others, etc" (I can only confirm it for "your posts," if it comes across an item which you can't delete it will not work) in order to have a bit of extra control over what is deleted.

    This post has been brief, details have been left out, but I did want to share this code so that it is out there in case anyone wants to build on it. If I had infinite time I would put this in a Greasemonkey script, and wrap it into some sort of easy to use user interface.

    Do note! I am definitely not a JavaScript developer. Despite all the languages I have written, and all the programming courses that I have taken, I have never made a serious attempt to learn JavaScript. In fact, I am very confused by it. For example, being able to have loops and delays in this script presented major difficulties which would have been a breeze in the other languages I have coded in. I am baffled by JavaScript, I am surprised the below works, I am positive there are better ways of writing this, and I suspect there are useless aspects of this script.

    Also note, you need to scroll down in your activity log, and reveal all the posts which you want to be deleted in order for them to be deleted. The script does not automatically load them in for you.

    Lastly, how do you know when the script ends? It crashes. hehe

    var to1, to2, to3, to4, to5;
    // $jq is the method of accessing JQuery after "JQurifying"
    function myStart(){
    function task1(){
        try {
            $jq('a[ajaxify*="show_story_options"]:first').attr('id', 'toryUnique1');
        } catch (err) {
            window.clearTimeout(to1); //no idea if these are needed
            window.clearTimeout(to4); // something dint' work right, just
            window.clearTimeout(to5); // start over. If something didn't
            myStart();                // work right it is probably because
            return;                   // a delay was too short
        to1 = window.setTimeout(function(){
        }, 800); //800 millisecond delay
    function task2(){
        try {
            $jq("a:contains(Delete)").attr('id', 'toryUnique2');
        } catch (err) {
        to2 = window.setTimeout(function(){
        }, 800);
    function task3(){
        try {
        } catch (err) {
        to3 =  window.setTimeout(function(){
        }, 400);
    function task4(){
        try {
            $jq('input[value="Delete"]').attr('id', "toryUnique3");
        } catch (err) {
        to4 = window.setTimeout(function(){
        }, 2000);
  • Thinkpad Disaster

    I thought I'd share my recent disaster story with the internet so that perhaps someone else can benefit from my misfortune.

    I was playing around with a PXE server a few nights ago so that I could host Linux ISOs on the LAN and boot off them so that I would not have to keep on making various USB Live CDs. Since this is a common occurrence I figured this would be a fruitful endevor.

    I had set up the server and it was time to test it out. I shutdown my Thinkpad X60 tablet and attemtted to modify the BIOS for network boot. I then realized that I had a password on there from probably about 5 years ago, a password which I no longer remebered. I thought no problem, I will just pull the BIOS battery and the password would be removed, no problem.

    I open up the machine, pull the battery and plug it back in and boot the machine. To my horror, I recieve a message to the effect of, "your device has been tamprered with please enter the BIOS password to continue." That is, the BIOS password I was attempting to remove because I no long remember it. Or in other words, I am locked out of my own machine at the hardware level

    Of course I have queried the internet on a possible remedy to my situation but to no avail. I saw one thing about being able to solder some wires to a particular chip and read the password off it via a secondary computer's serial port in combination with a few other minnor electronics but my model was not listed in this tutorial and I could not find the chip upon inspection of the motherboard. I also read that I could have the motherboard replaced to remedy the situation. However, neither of these two solutions were time or money efficient for me and my life right now.

    I was quite surprised that this happened but I am glad that my computer savvy friends have not said 'well duh' when I tell them the story. It was an extremely embarassing mistake, though it is hard to blame myself since it would appear that many people too were not familiar with that behaviour, though I am sure this could have been obvious to Thinkpad technicians.

    What I do not fully understand is what purpose does this serve? I mean, I assume people place passwords on their computers to protect the data not the hardware and this feature that I have been caught up in does not accomplish much in the way of protecting my data. In fact, I just finished retreiving my data from the hard drive which was in the machine at the time by connecting it to another machine via a SATA-USB adapter. Doing so did require the encryption key I used to encrypt the drive, so, my data was secure, but this security was not provided by the BIOS. I also suppose, and perhaps this already exists, that the hard drive could be cryptographically paired with security chip on the motherboard, and if that were the case I could see the BIOS password making sense. Or maybe this feature was available and I did not realize it. But keep in mind, this machine came pre-installed with Windows XP, a time where I do not recall encrypted hard drives being common place. It seems to me that I have in vain been permanently locked out of an old, both otherwise perfectly good machine.

    Bottom line: Be careful when unplugging the BIOS battery of a laptop!

  • ubuntu virtualbox kernel driver not installed

    I ran into some issues with getting Virtualbox to run. I'm not sure why it stopped working, it seems like it might have been because a new kernel was installed, I'm not sure. However, I fixed it, it seems as if I was missing the new kernel headers. Bellow you will find the two commands I think fixed the situation, hwoever, there were a few others I ran in the process of troubleshooting.

    # apt-get install linux-headers-$(uname -r)
    # /etc/init.d/vboxdrv setup
  • Rotate Cellphone Video

    For whatever reason every time I have shot a portrait mode video with my Motorola Atrix cellphone. Today the issue came up again and here is the command I finally used with acceptable success.

    ffmpeg -i 2012-03-16_15-12-41_472.mp4 -vcodec libx264 -preset medium -crf 24 \
     -threads 0 -vf transpose=1 -acodec copy output.mkv

    It isn't perfect, but, it is good enough, I hope this helps

  • Firefox New Window Cursor Search (Omnibar)

    I am using the Omnibar extension in Firefox which gives Firefox a Chrome like search/address/location bar. When I open a new window I want the cursor position to default to this bar. In order to do this, in Firefox I set the default hompage to blank, and when I did that, the cursor was put in the Omnibar instead of on the homepage which was loading

  • Firefox New Window Middle Click Link

    double click "browser.tabs.opentabfor.middleclick" in "about:config" to cause middle clicking links to cause a new browser window to open rather than a tab.

Page: 3 of 6