James Fishwick

  •  Minimal
  •  CSS Tomfoolery

Automating swfdump to bulk generate flash dimensions or other metadata

Code Snippet, linux, Note to Self, Production Automation

No Comments


Share this post

Using a MarkLogic application at work to manage and deploy content. We have almost no available metadata nearly any of our thousands and thousands of video and flash content. We’re generating it by hook or by crook, often repurposing editorial transmittal grids into csv for import. Needless to say, stuff like native dimensions or the like have been lost in the sands of time – existing html embeds are done in a multitude of slapdash ways, with height and width varying greatly per instance.

I should also say that this is all legacy content being shoehorned into “responsive” courseware. So there are width restrictions now, when before these activities were just popped up in new windows with “100%” widths.

Anyway, when trying to place said swfs into the product, the embed codes for an entire disciple were completely wrong. Things squished, white spaced abounded. Turns out the person who loaded the original metadata set all the widths to the max width for the product (595 px) and then grabbed heights from the questionable html wrappers. But they didn’t in turn adjust this grabbed height in light of a new width. Oooooof. A complete mess!

I needed to start from scratch, but I was looking at several hundred swfs. Grepping the dimensions from the html was out, as they were suspect. As was opening each in Flash, I refuse to do manual labor! I needed a csv with all the filenames and native dimensions. If the width is over 595px, I needed an aspect ratio calculation done.

So swfdump and bash to the rescue!

Read more

Can regex even match a null character?

CLI, Code Snippet, Note to Self

No Comments


Share this post

Yes.
\x00
That is a null char and you can match it with any PCRE engine. Note that most visual tools, like Dreamweaver etc, won’t handle this well, and won’t even display it. In fact, most will stop processing the file when they hit the null character.

The exception being the mighty Notepad++. So use that if you’re afraid of the CLI.

Read more

Converting Strings into Numbers

Code Snippet, Javascript, Note to Self

No Comments


Share this post

You need to convert a string to a number.  Several ways, with varying purposefulness:

Number constructor called as a function simply performs type conversion:

// type conversion
Number("911");        // 911
Number("20px");       // NaN
Number("2e1");        // 20, exponential notation
Number("010");        // 10 (The Number constructor doesn't detect octals)
Number("8,569")       // Nan
Number(8,569)         // 8
Number("8.569")       // 8.569
Number("0xF");        // 15 (But it can handle numbers in hexadecimal notation)
Number("false");      // NaN
Number(true)          // 1

parseInt() performs parsing into an integer*:

// parsing:
parseInt("999");        // 999
parseInt("20px");       // 20 (will stop parsing and drop any part of the string it can't figure out)
parseInt("fi5e")        // NaN (string has to start making some sense right away)
parseInt("10100", 2);   // 20
parseInt("2e1");        // 2
parseInt("010");        // 8 (if parseInt detects a leading zero on the string, it will parse the number in octal base)
parseInt("010", 10);    // 10 (decimal radix used)
parseInt("0xF");        // 15 (can also handle numbers in hexadecimal notation
parseInt("22.5")        // 22 (because the decimal point is an invalid character for an integer)
Number("false");        // NaN
Number(true)            // NaN

*It’s always a good idea to supply a radix to parseInt(value, radix) that way you don’t have accidental octal mode conversions.

The parseFloat() method works in a similar way to parseInt() however the string must represent a floating-point number in decimal form, not octal or hexadecimal.

parseFloat("1234blue"); 	// 1234.0
parseFloat("0xA"); 	// NaN
parseFloat("22.5"); 	// 22.5
parseFloat("22.34.5"); 	// 22.34
parseFloat("0908"); 	// 908
parseFloat("James1980"); 	// NaN

The Unary Plus method (+num) is basically a short cut for casting to a number via Number(). Just a nice shortcut really.

+"911"; // 911
+"20px";       // NaN
//etc etc
num = 1 + +"2"; // num is assigned the value 3
+true; // 1 (just saying...)

Finally, you can attempt some simple math on your string, does the same as the above.

"123" / 1; // 123
"123.987" * 1; // 123.987

You can use num / 1;, num * 1;, 0 + num; or 1 * num;.

If you’re interested in a speed comparison, see this test case (this would only matter for huge numbers of conversions. HUGE.)

Read more

Web App mode leaves users stranded when following image links when using WPTouch with W3 Total Cache

Note to Self, Page Performance, WordPress

No Comments


Share this post

In most of the posts on my client’s site, embedded images link to the actual image file. I’ve also enabled Web-App mode via WPTouch. In web-app mode images linked to their larger versions shouldn’t open; since Web-App mode has no back button, a user can follow a link to a image and become “stranded” there.

I’m also using W3 Total Cache, which appends the param string like “?9d7bd4″ to all my images. This makes sure that if you change your browser cache policies all users immediately see that change.

However, apparently the appended image string allows for the images to be clicked on and stranded. Interferes with whatever is stripping the image links.

Best way to avoid this:

Go to “Browser Cache.”

At the bottom, you have checked the following setting:

Prevent caching of objects after settings change
Whenever settings are changed, a new query string will be generated and appended to objects allowing the new policy to be applied.

This adds an appropriate string to the end of all images called through CDN or otherwise. Uncheck that box and purge/refresh the cache to see the difference.

Yay. Be stranded no more.

Read more

bash find and boolean operators

CLI, Code Snippet, Note to Self

No Comments


Share this post

Just because it took me way too long this morning to figure out how Boolean operators work with find.

Suppose I want to find the files with .png and .jpg extensions.

Its not

$ find /path/ -name '*.png' -and -name '*.jpg'

but

$ find /path/ -name '*.png' -or -name '*.jpg'

The “-and” refers to one set of file names where both conditions are met (as if we didn’t use the boolean at all). The “-or” says I’m looking for either/both of two sets.

So to explain further:

Read more

Conditional Tags for Custom Post Types & Taxonomies

Code Snippet, Note to Self, WordPress

No Comments


Share this post

Most WordPress instances used to power a full site or shop will hopefully take advantage of the power combination of Custom Taxonomies and Custom Posts. Often you want to style a list of your Custom Posts by Custom Taxonomy and have the single view styled in the same way, or perhaps have the same sidebar. You can do this with by leveraging the Template Hierarchy and registering tons of sidebars. However, before long, you can find your theme folder bloated with extra templates. I don’t like having tons of templates in my themes. Too much code duplication usually. Rather, I like to use Conditional Tags and get_template_part. When dealing with Custom Taxonomies & Post Types it may not be clear at first how one can best use Conditional Tags to good use. Lets take a look.

Read more

check if checkbox/radio is checked using jQuery

Code Snippet, jQuery, Note to Self

No Comments


Share this post
//returns true or false
$('"input[type=radio]').is(':checked');

$("input[type=checkbox]:checked").each(
    function() {
       // do something at each checked radio or checkbox
    }
);

Read more

Modernizr and jQuery and wp_enqueue_script oh my

Code Snippet, Javascript, Note to Self, WordPress

No Comments


Share this post

Some questions on the best way to use Modernizr with jQuery in the context of WordPress…

I want to be able to use jQuery in my complete callbacks. I, of course, want to be able to use wp_enqueue_script.

Read more

Committing to WordPress svn via proxy

Networking, Note to Self, WordPress

No Comments


Share this post

Multiple times when I was recently updating my svn repository for my Jetpack Easy Playlists plugin, I wasunable to connect to the WordPress SVN repository and execute basic svn commands. Kept getting warnings that looked like this:

svn: warning: Error handling externals definition for XXXX
svn: warning: PROPFIND of '/!svn/XXXX/default': could not connect to server (http://plugins.svn.wordpress.org)

Strangely, I was able to browse the repository via my browser, as well as checkout other public svns. I’m not behind a proxy, with a normal COMCAST connection.

What gives and how did I get around it?

Read more

textutil use cases

CLI, Note to Self, Production Automation

No Comments


Share this post

I don’t use my Mac as my main development/production workstation anymore, but its still my one-stop shop for all matter of text conversions.

While I have a very specific and regular use-case for textutil, namely converting Word .docs into barebones HTML or PDFS, there are plenty of features that make it a highly useful and general purpose tool. textutil can convert from/to txt, html, rtf, rtfd, doc, docx, wordml, odt and webarchive.

The basic syntax is:

textutil -convert fmt filename

Read more