Archive of articles classified as' "Code"

Back home

Quickly whitelist sites in Kill-Flash

7/06/2010

Is it hypocritical of me to write about a Flash blocker when I’ve spent a good portion of my time the last four years doing Flash? Maybe, but some of the sites out there have ridiculous amounts of intrusive and annoying banner ads, and I just can’t stand having my the fans on my Mac blowing a fuse every time I want to check out the news.

My favorite implementation of Flash-blocking has always been ClickToFlash which is a Safari-only plugin that works exactly as advertised. You click the element to load Flash. Sadly, as mentioned, it’s Safari-only and my browser of choice these days is Google Chrome.

Jason 128Fortunately I found a port, or perhaps a backwards engineered version for Chrome named, somewhat more aggressively, Kill-Flash. It works on exactly the same principle. All Flash elements are replaced with an inconspicuous grey-scale gradient with the label “Flash”, and you “Click To Flash”… Duh.

Stupidly however, I have found no simple way to add sites to the plugins whitelist. A few sites (YouTube and GMail) are whitelisted by default, but no option that I’ve found to add new sites. There are several sites I visit on a regular basis and where I want to see the Flash. Hell, my own blog uses several (subtle, I hope) Flash elements and I don’t need to see those grey boxes every time I come here. In fact, personally I think perhaps a “blacklist mode” would be my preferred way to operate.

So, anyway. I started digging around in the Library to figure out how to add sites to the whitelist. The first issue of course is to find out where the whitelist is located. A couple of headscratches later I found that this is the file you need to deal with:

/Users/USERNAME/Library/Application\ Support/Google/Chrome/Default/Extensions/kfncbcioneejfnnelcdmocdjncbmceea /1.1/kill_flash.js

I’m not sure whether or not that crazy string is the same for everyone or generated randomly for each installation. If you see the kill_flash.js you’re there.

Opening this file reveals, at the very top the following variable.

1
var whitelist = ["www.youtube.com","mail.google.com","gmail.com"];

What you need to do is simply append the domains you want to whitelist to this array, in quotes and separated by commas. Like so:

1
var whitelist = ["www.youtube.com","mail.google.com","gmail.com", "ctrloptcmd.com"];

When you’ve done this you might want to create an alias for easy access to the file. Personally I just dragged it to my Dock for the sake of convenience.

I might at some point write an AppleScript or something to make this easier. If that ever happens I’ll be sure to post it here.

No Comments

JAPH – Awesome Code Obfuscation

6/06/2010

Every so often I stumble across something that really just leaves me dumbfounded. The only valid response seems to be “… Fascinating!”

The latest is this clever JAPH consisting solely of keywords.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
not exp log srand xor s qq qx xor
s x x length uc ord and print chr
ord for qw q join use sub tied qx
xor eval xor print qq q q xor int
eval lc q m cos and print chr ord
for qw y abs ne open tied hex exp
ref y m xor scalar srand print qq
q q xor int eval lc qq y sqrt cos
and print chr ord for qw x printf
each return local x y or print qq
s s and eval q s undef or oct xor
time xor ref print chr int ord lc
foreach qw y hex alarm chdir kill
exec return y s gt sin sort split

In short; The Perl community has a meme going where you are supposed to write a snippet returning the String “just another perl hacker” in the most convoluted and obfuscated way possible.

This gem does exactly that. It’s beautiful in that there are no Strings in there, only valid Perl keywords, and it’s perfectly justified. For some reason this kind of useless stuff really appeals to me at a deep level. I fear a couple of hours may be lost to trying to create a clever JAAH.

This was posted earlier on ria.creuna.com.
1 Comment

The Parallax WordPress theme open sourced

4/06/2010

I’ve been meaning to release the theme of this blog for ages, yet I never really got around to finishing it.
After a bit of consideration I’ve decided to go for the easy option and just release it “as is”. It’s based on Sandbox and is therefore GPL-licensed. Otherwise I’d release it under my personal “I don’t give a hoot, but please credit me”-license.

If you want to use this theme for your blog without making any changes, here’s what you might be interested to know:

  • The text in the top banner is entirely configurable in the theme options. You can even choose between using Flash, a static image file (there’s a template included in the theme folder) or even plain HTML text
  • The Twitter widget in the sidebar is likewise configurable. Enter your Twitter ID, choose whether or not to ignore @replies and Bob’s your uncle.
  • This theme is not widget ready. If you try to add widgets they simply won’t show up. The default Twitter, Feeds, Recently and Pages is what you get. I’m sorry about this. This was one of the things I was working on when I ran out of time.
  • I’ve tried to clean out most of the plugin-specific styling for the plugins I use. Simply delete the following files if you don’t want my plugin-styles to override the defaults:
    • styleextras.css
    • sociable_see_extras.css
  • Like I said; Work in progress. Here be dragons. :)

If, however, you want to help out finishing this theme and / or add your ideas to it here is a list for you.

  • The reason widgets don’t currently work is because I wanted to make it so that widgets would always be styled in a specific manner according to their position, rather than the type of widget. For example I wanted the next box on the right to be grey regardless of whether it was an archives widget or a recent posts widget. Anal much? Yes. Anyway; I made a JavaScript that assigns an extra class to each widget based on it’s position, or “number” if you please. It’s pretty much done except for making the graphics (getting the design to be height-agnostic is a real bitch). There’s some first attempts in the images folder if you want to give it a go
  • The theme does not currently validate properly. It used to, and then I messed something up. Sorry.
  • The comment styling is really messy. I’d consider working it over if I were you. (I’ll get around to it some day…)
  • There’s probably more I should warn you about, but it’s late and I’m sleepy. I created this theme strictly for personal use, and although I’ve gotten rid of all absolute URLs and site-specific stuff I haven’t gotten around to cleaning up the code. I’m quite the salesman, huh?

So there it is. For the geeks, here’s a github link.
For the non-geeks, here’s a direct download to the theme zip-file.

Enjoy.

No Comments

A few random AppleScript snippets

14/01/2010

I was just writing an AppleScript to look up words on the excellent NinjaWords and decided to post it in case someone else needs something similar. Since one snippet of AppleScript is not a very meaty post, I’ll throw in a couple extra.

Look up word on NinjaWords

Select a word and copy it to the clipboard. Then invoke this script via Quicksilver or LaunchBar or whatever is your favorite tool for invocations.

1
2
3
4
set clip_url to (the clipboard as string)
set lc_url to do shell script "echo " & clip_url & " | tr '[:upper:]' '[:lower:]'"
set ninjaURL to "http://ninjawords.com/" & lc_url
do shell script "open " & ninjaURL

Wrap link in ‘a href…’

Note: This one will look slightly different depending on whether you are using Quicksilver, LaunchBar, whatever. The key is that you pass a string value into the script and it returns one back to you. This example is for LaunchBar.
Copy a link to the clipboard, invoke the script, paste your now a-tagged link.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
on handle_string(vanillaStr)
  set quote to ASCII character 34
 
 
  set openTag to "<a href=" & quote
  set closeTag to quote & ">"
  set finishTag to "</a>"
 
  set TempTID to AppleScript's text item delimiters
  set AppleScript's text item delimiters to space & ":" & space
  if (count of text items of vanillaStr) is greater than 1 then
    set urlStr to text item 1 of vanillaStr
    set linkStr to text item 2 of vanillaStr
    set returnStr to openTag & urlStr & closeTag & linkStr & finishTag
  else if (count of text items of vanillaStr) is 1 then
    set urlStr to text item 1 of vanillaStr
    set linkStr to "linkage"
    set returnStr to openTag & urlStr & closeTag & linkStr & finishTag
  else
    beep
    return
  end if
  set AppleScript's text item delimiters to ""
  tell application "LaunchBar"
    perform action "Copy and Paste" with string returnStr
  end tell
end handle_string

New File

Sometimes you just want a dang text file to magically appear.

1
2
3
4
5
6
7
8
9
10
11
12
try
  tell application "Finder" to set the this_folder ¬
    to (folder of the front window) as alias
on error -- no open folder windows
  set the this_folder to path to desktop folder as alias
end try
tell me to activate
set thefilename to text returned of (display dialog ¬
  "Create file named:" default answer "filename.txt")
set thefullpath to POSIX path of this_folder & thefilename
do shell script "touch \"" & thefullpath & "\""
do shell script "mate \"" & thefullpath & "\""

That’s it for now. I have some gems saved for a later post, but they wouldn’t make sense out of context so you’ll just have to wait.

2 Comments

Set up your own lifestream using FriendFeed and… Dirty hacks

10/01/2010

Lifestream
When Iceland went bust and started selling .is domains I grabbed martin.is. Of course I did. That’s the kind of guy I am. Even as I swiped that credit card (and by “swipe” I mean “typed in all my info into the appropriate boxes.”) I knew I had no idea what I was going to use it for, but what the hey; I’ve done plenty of even stupider domain purchases that never led to anything1.

So finally, the other day I decided to set up a “lifestream”. An aggregate feed of all the highly interesting stuff I do on the web. Not because I think anyone particularly needs or wants to know. It just seemed like the kind of thing that goes on a domain called “martin is”.
I really didn’t want to spend loads of time on this. I have a job, a daughter and a blog that are all already wailing for my attention, so tried plugging all my stuffs into a WordPress install using FeedWordPress and a couple of other similar plugins, but I found the results to be (unreliable | explosive | bewildering)2.

Alrighty then. What services do I know of that aggregate information like this? FriendFeed! I headed over to FF, and sure enough; Within half a minute I had managed to plug all the crap I generate into one massive hunka’data. In addition to supporting a bunch of services Friendfeed actually does pretty well parsing feeds from other sources and cutting the entries into little blurbs. Now only to get it out of there and onto my domain.

Read the rest of this article »

  1. Seriously. Need a domain?
  2. Pick one.
No Comments