Slimy: another html5 slideshow

After seeing a coworker’s presentation completely done using html5 and javascript, I really realized how much of a platform that html5 can be. Effectively, it’s a ubiquitous platform by which any operating system can run code, with very little prior setup necessary. I really liked the concept of an html5 slideshow, so I looked around for one that suited my needs. There wasn’t one, so I began to write my own. I present Slimy:

http://code.google.com/p/slimy/

You can see an example here:

http://slimy.googlecode.com/git/example.html

I explored html5 slideshows quite a bit, and I had two main issues that got me interested in writing my own:

  1. Every html5 slideshow I saw had online dependencies. I understand that the web is everywhere, but I still didn’t want to rule out situations where internet access is not readily available. Simply saving the slideshow locally with a browser was a viable option, but I preferred to also clutter my file system as little as possible.
  2. The markup wasn’t always straightforward. I was recommended both the google html slideshow and rubyforge’s slideshow, but I didn’t like the idea of having to learn a different proprietary markup, especially when html is about as simple as markup gets.
  3. The slideshows included little fixes to make up for css3 technologies that weren’t supported. I didn’t like this. I was looking for something that doesn’t sacrifice simplicity to try to make the code work for less standard-compliant or outdated browsers. My system works for the newest browsers, and I don’t imagine that changing.

Slimy focus’s on encapsulation of the slideshow, and also functionality. My main goal is to make it as functional as Google’s html5 slideshow, but much simpler and elegant. I aim to keep it that way by including as few proprietary functionality as possible, instead relying on css3 and javascript such as css transitions. I do require jquery, but I think it makes the functional code significantly more elegant and readable.

I would love to see some feedback, and I am willing to add more functionality as requests come in. So please, give slimy a shot! I have a feeling you’ll rarely use Powerpoint or any other slideshow application again.

Categories: Coding, General Tags:

Passing perforce batch files

My coworker showed this to me today: if you want to use a perforce command from the command line, and pass it a batch of filenames from a command (such as find or grep), simply use:

p4 COMMAND ${ENTER_COMMAND_HERE}
Categories: Uncategorized

Automatic Package installation using ELPA in Emacs 24

February 16, 2012 Leave a comment

Emacs 24 includes many improvements over 23, but there is one particular addition that makes me run around and go crazy with joy: a built-in package management system, ELPA (Emacs 24 is still in development, Bozhidar Batsov has a good guide on how to get it set up). I switched over to Emacs almost a year ago, searching for something that would give me an IDE with the following attributes:

  • Functionality (context-based completion, on the fly syntax checking)
  • Customization (key bindings, easily extensible)
  • Portability (minimal setup on new environments)

There are a lot of nice extensions that do well for the first two. However, Portability was always tricky. To get some of the more power coding features in Emacs, one needed to install large packages, and there was no way to move these around short of zipping the whole thing up or finding and installing all these packages again.

ELPA completes the trifecta I have been looking for. It was now easy to have a list of packages to install. I have a GitHub repository to contain all of my .emacs setup, so I can just clone a repository with every new environment. To make the setup completely automatic, I needed a method to automatically install packages that did not exist. After a little research, I was able to figure it out:

;; Packages to install first (check if emacs is 24 or higher)
(if (>= emacs-major-version 24)
  (progn
  ;; Add a larger package list
    (setq package-archives '(("ELPA" . "http://tromey.com/elpa/")
      ("gnu" . "http://elpa.gnu.org/packages/")
      ("marmalade" . "http://marmalade-repo.org/packages/")))
       (package-refresh-contents)
       ;; Install flymake mode if it doesn't exist, then configure
       (when (not (require 'flymake nil t))
         (package-install 'flymake))
       (global-set-key (kbd "C-; C-f") 'flymake-mode)
       ;; flymake-cursor
       (when (not (require 'flymake-cursor nil t))
         (package-install 'flymake-cursor))
       ;; Install rainbow mode if it doesn't exist, then configure
       (when (not (require 'rainbow-mode nil t))
         (package-install 'rainbow-mode))
       (defun all-css-modes() (css-mode)
         (rainbow-mode))
       (add-to-list 'auto-mode-alist '("\.css$" . all-css-modes))
    )
)

NOTE!!! This must be run after ALL OTHER INITIALIZATIONS are run! You can do this by placing it within a hook:

(add-hook 'after-init-hook '(lambda ()
	  (load "~/.emacs.loadpackages"))) ;; anything within the lambda will run after everything has initialized.

As you can see, I’ve put the above logic into a file called “.emacs.loadpackages”. This is so I can remove it at easy if I want a more bare environment.

I’d like to talk about this a little bit in detail. The first line ensures that emacs is version 24 or higher:

(if (>= emacs-major-version 24) PACKAGE_STUFF_HERE)

I then add more repositories to the package manager, gnu and Marmalade (the base package is a bit limited, in my opinion)

(setq package-archives '(
    ("ELPA" . "http://tromey.com/elpa/")
    ("gnu" . "http://elpa.gnu.org/packages/")
    ("marmalade" . "http://marmalade-repo.org/packages/")))

This requires a refresh:

(package-refresh-contents)

And then onto the logic to see if a package exists! You can use require to see if a package exists, nullifying the error message it usually return by adding the true statement at the end. For example, this will return true when the package fly-make cursor is not installed:

(not (require 'flymake-cursor nil t))

You can then add this to a complete clause:

(when (not (require 'flymake-cursor nil t))
    (package-install 'flymake-cursor))

And you’re done!

Issues:

There a couple of things I’m still working on regarding this setup. Although I haven’t gotten any environment breaking errors so far, there’s not a lot of error checking, so I’m sure it can break if things are not completely right. In addition, this does not work very well for portable programmers, as Emacs will try to initialize ELPA, resulting in an exception due to not being able to contact the server.

Please leave comments and suggestions!

 

Categories: Uncategorized

Python Pet Peeves

January 26, 2012 Leave a comment

As of this posting, Python has been my main programming language for over three years. Although I definitely feel that Python is not a good fit for all programming projects, the speed and efficiency with which I can code in it has made it my go-to language whenever possible.

As such, I’ve seen a lot of Python code, and have had ample time to think about some of the more nuanced issues regarding coding standards. Here’s a few of my pet peeves, and opinions about them:

from module import *

When I first started python, I used this particular import for a lot of things. I’m using so many methods from this module, why not just import the whole thing? It was definitely a pain in the neck fixing those include issues.

Well, time in the industry has made me realize the error of my ways. This isn’t just python related, this is related to any programming language. Includes/Import should always be as obvious as possible. The correct import methodology, is to do as such:

from module import w,x,y,z

or, if you want to be even nicer:

import module
module.x()

But what if we’re using ten methods from that module? still gotta do it.
What about 20 methods? still gotta do it
What about 100 methods? don’t know how there’s 100 methods in a single module, but you still gotta do it.

The reasoning is simple: you’re providing a very helpful hint that future coders can use to debug your code years from now. That hint is : where the method is actually found.

While you yourself don’t save any time off of doing this, you’re saving hours of development time for future coders, giving them a roadmap to exactly what your function’s stack actually is. Although this can be given by any IDE that has an understanding of the language and it’s dependencies, one shouldn’t assume that this is so. In my experience, when debugging, I have spent anywhere between a good ten to twenty minutes looking for methods, especially in python files with twenty lines of imports. To know exactly where a particular method or module comes from goes a long way to making one’s code maintainable.

For example, suppose I was a programmer who had to debug, and was able to pinpoint the bug to a method that had been previously written, called a_func. The file calling it looks like:

from foo import *
from bar import *

def b_func():
    ...
    a_func()
    ...
    return

Now if I had no knowledge of the modules foo and bar, I would have to look through BOTH foo and bar, and see if either of those had the function a_func. This is only a minor inconvenience if your code only has two of these imports, but the larger a script gets, and the more includes it brings in over the years, could result in one having to look through several files in various locations, to debug one call. Precious time that could have been saved, had the original code just written:

from bar import a_func

Use ternary’s, but only where it makes sense

If you’re not familiar with tenary operators, I’d suggest acquainting yourself now. After all, ternary operators only exist because the problem they solve is so prevalent in coding everywhere. Specifically, the strict point where you want a variable to be one of two things. In Python, ternary operators are represented differently than other programming languages (the typical ( condition ? do_this_if_true : do_this_if_false ) operation). Python has:

do_this_if_true if condition else do_this_if_false

Ternary’s in general have several uses. The big one is providing a default value:

var = (value if value else default_value)

Basically, in any situation where you have:

if this:
	just_one_procedure()
else:
	just_one_other_procedure()

One should consider using a ternary. You can also nested ternarys, although I wouldn’t suggest doing so for more than one level deep. This is especially useful when you have a variable assignment with four different possible outcomes:

x = ( (1 if a else 0) if b
else (2 if c else 3))

To do so with regular if else statements, one would need ten lines of logic. Ternarys are a lesser known function within Python, and it belongs in any programmer’s set of tools.

Categories: Coding, Python

Search and replace multi-line expressions with SED

October 26, 2011 1 comment

Now here’s an interesting problem:
I wanted to do a recursive search and replace in unix, AND I wanted to do an expression that spans multiple lines. Here’s what I came up with:

find ./ -type f | xargs sed -E -i -n
'1h;1!H;${;g;s/<\/fileSet>.*<fileSet>.*RevisionVersion.*
<\/fileSet>.*<\/fileSets>/<\/fileSet>\n<\/fileSets>/g;p}'

There a lot of examples showing you how to do this.
The first argument lists all files recursively. These are the piped to sed, which uses an inline search and replace (-i or –in-line), then using the expression ‘{}’ which is then modified for multi-line expressions (1h;1!H;).

WebPageTest and IE9

October 25, 2011 Leave a comment

Recently, I tried updating the browser for a WebPageTest instance to IE9. This proved to have some issues, specifically due to the pop-up dialogues that IE9 has now to tell you when something suspicious occurs.

Logging into WPT, I was greeted with an error on an IE9 browser opened by URLblast. Something along the lines of:
“Are you sure you want to use this Non-Verified plugin?”

Of course, the non-verified plugin was the WebPageTest hook. In order to get that working, I modified the security settings on my browser to not care about non-verified plugins:

Internet Options (clicking on that gear icon in IE9) -> Security -> Custom Level.

I modified two settings:

  • “Download unsigned ActiveX controls” to Enable (not secure)
  • “Initialize and script ActiveX controls not marked as safe for scripting” to Enable (not secure)

This then brought me to another error, with IE9 complaining about not using secure settings. Something like:

“Your current settings are insecure”

Well, after some searching, there’s apparently a policy that you can set that disables this specific message:

http://windowsconnected.com/forums/p/959/3087.aspx#3087

Basically it says:

Run gpedit.msc (if you type ‘gpedit.msc’ in the search bar it comes up)

Then Navigate to Computer Configuration -> Administrative Templates -> Windows Components -> Internet Exporer, and right click and enable the “Turn off the Security Settings Check feature” policy.

This gets rid of the error, but then WebPageTest just seems to freeze on a run. After some more searching, there was one final step in the solution. It seems that urlblast has to open the browser using the user’s account. By default, urlblast creates and uses a specific account on which it opens a browser, not necessarily the user that is running urlblast. Having the account opening the browser be an administrator did the trick, and in my situation, I just had it be the same account running urlblast. This can be done with a change in urlblast.ini:

Use Current Account=1

And that did it for me!

Categories: General

Getting Python2.5 to Build with sqlite3 and zlib on Ubuntu Natty 2.5

September 19, 2011 Leave a comment

I had a really hard time finding this, so I’m posting it here:

First one must install all the proper packages on Natty (these are the packages needed for zlib and sqlite in general, not just specifically for Python):

sudo apt-get install zlibc zlib1g zlib1g-dev
sudo apt-get install sqlite3-dev

Then one must add an LDFlag to the new lib directories (apparently Natty has a new directory for X86_64 lib files):

after the ./configure open your Makefile and find the line with
LDFLAGS =

edit to LDFLAGS = -L/usr/lib//x86_64-linux-gnu

and make

Credit for the above snippet goes to Awin Abi and source is below:

http://groups.google.com/group/google-appengine/browse_thread/thread/a8bd0a71270a3ce6

Basically, setting up Python2.5 ( and presumably any version of Python) properly involves downloading the proper package libraries , then building Python2.5 with those packages. In order to do this, the LDFlags variable must have the new library location (the /usr/lib/x86-64-linux-gnu) for Natty and 64-bit processors added.

I have not tried this on a 32-bit machine. This may not be required then, or you may need to point the flag to load the proper directory.

Categories: Coding, General Tags: , , ,
Follow

Get every new post delivered to your Inbox.