Endorkins

The coder’s high

Endorkins header image 1

Safe Driving and Coupons Website

July 22nd, 2011 · No Comments

Just a bit of a plug here for you to check out a site that I’ve been working on for a client. It’s called Collision Guard, and it’s a safe driving and auto discount website. I joined the team after the site had been live for a few months on a feverishly hacked together infrastructure of very repetitive and inefficient PHP and jQuery. This was back in late 2010; I’ve been working on the site ever since.

Since joining the team, I’ve pretty much rewritten the site from scratch. Some notable aspects of the setup:

  • Fast cached geolocation via Maxmind’s API
  • Extensive usage of RedBean (a PHP ORM; very nice, but definitely not perfect)
  • A custom templating system
  • Seamless integration with WordPress
  • Custom statistics tracking
  • Custom bulk emailing with tracking
  • Some fairly fancy backend jQuery interfaces (those in the automotive industry are not very tech savvy)
  • etc.

Anyway, it’s been a fun site to work on, and Brian and the gang have been super team members.  Make sure to check out the site, learn about texting while driving, download some oil change coupons, and let me know what you think. :)

→ No CommentsTags: Uncategorized

Facebook Graph API – Upload Photos – “Requires upload file”

December 28th, 2010 · 4 Comments

Quick post here since I see a lot of questions about this out there.

If you’re trying to upload photos via Facebook’s Graph API and you’re getting an OAuthException with a message of “(#324) Requires upload file”, I can help you out.

Something seems to have changed with facebook.php recently – if you’re going to upload files, you have to explicitly set fileUpload to be true in the API. In my setup code, I just add a line as demonstrated below:

// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
'fileUpload' => true,
));

Alternatively, if you’ve already set up your $facebook object, you can call:
$facebook->setFileUploadSupport(true);

Happy coding!

→ 4 CommentsTags: Uncategorized

Slow Excel Spreadsheet? Try this.

July 13th, 2009 · 5 Comments

There are a number of things that can cause an Excel spreadsheet to slow down. Sometimes, the spreadsheet can become unusable, requiring up to a minute for saving or even the most basic of changes. Here’s a brief checklist of the most frequent causes of Excel slowdowns.

(Have a spreadsheet slow-down that I haven’t described below? Let me know in the comments! Thanks! :) -Rich)

  • Network problems. If the spreadsheet is accessed over the network (local or remote), network issues can delay saving.
  • Macros/VBA code. If you are using macros (or Visual Basic for Applications), make sure you don’t have unnecessary macros running, or macros that perform unnecessary calculations.
  • Burdensome animation. Try disabling animation. 2003: Tools > Options > Edit > Turn off “Provide feedback with animation”. 2007: Excel Button > Excel Options > Advanced > General > Provide feedback with animation (uncheck)
  • Complicated calculations. If you’re doing lots of calculations, you can disable auto-updating of these calculations. When you do so, your spreadsheet will not update until you explicitly desire (e.g. when you hit the F9 key). To disable auto-updating in 2007, go to the Excel Button > Excel Options > Formulas > Workbook Calculation, and select “Manual”.
  • Duplicate Conditional Formatting Rules. Conditional formatting can be a processor-intensive task if your rules aren’t set up right. Manage your conditional formatting rules (2007) via the ribbon at Home > Conditional Formatting > Manage Rules… Try to consolidate similar rules into one rule (e.g. a rule for an entire column instead of a rule for each cell in the column)
  • Funky Formatting. Formatting can really slow down a spreadsheet, especially on slower machines. Try removing all formatting: Removing All Formatting.
  • Unnecessary junk. Sometimes, an Excel file can become backlogged with a bunch of unnecessary junk. Try saving as a CSV (comma-separated) file, which will strip out everything except for the data. (Make sure to not save over your original file in case this workaround does not, well, work! :) )
  • Unknown, but it seems to help sometimes. Install the Lookup Wizard add-in.
  • Other issues. Do you know of another issue that causes Excel to slow down? Let me know in the comments!

Assorted helpful links:

→ 5 CommentsTags: Uncategorized

Drupal(jQuery UI + Devel): $.widget is not a function

May 7th, 2009 · 5 Comments

jQuery whines incessantly

croppercapture14

Real helpful error. I’ve verified that $.widget() is a function and has been included. So, why am I getting this error? (In fact, now that I think of it, Javascript/jQuery has the most obtuse and misleading error messages of any language I have ever programmed in. However, it’s also one of the most ubiquitous languages as well. Interesting.)

Enough meta whining; what’s the problem?

Drupal developers love jQuery, and hence the jquery_ui module. They also love the Devel module. Unsurprisingly, the developers of the Devel module love jQuery UI as well, and have included portions of the UI API directly within the Devel module. This works nicely until you decide that you love the jQuery UI, and install jquery_ui. When you call jquery_ui_add(array(…)) from your code, if you include any files that the Devel module has already included (an outdated version thereof, I might add), then you’ve got two (nearly) identical files of included code that clash brilliantly.

And hence the lovely error, “$.widget is not a function”. Wouldn’t “$.widget is already defined” make a bit more sense?

Fix it, fix it, fix it!

Fortunately, there are many ways to fix this error.

  • Write a patch/Get the authors of the Devel module to add the jQuery UI module as a dependency (and remove the direct jQuery UI includes from the module). Easily the best, but most time-consuming solution.
  • Write a patch/Get the authors of the jQuery UI module to check if a given jQuery UI file has already been added via drupal_add_js(). If it has been, don’t include the file again. Might still cause conflicts because of differing versions
  • Hack the Devel module:
    • Enable the jQuery UI module, and remove the code from the Devel module that includes the jQuery UI files local to the Devel module
    • Replace the jQuery UI files in the Devel module with the same files from your jQuery UI installation. Then, in your code, only include the files that the Devel module uses (ui.draggable.js and ui.mouse.js currently) if the Devel module is disabled. This solution takes a bit of effort but might be the quickest workaround.
  • etc (I’m sure there are many more options)

Personally, I’m using the last option. The code I’m using to detect whether or not the Devel module is enabled (and act accordingly) is:

	if(function_exists('devel_menu'))
		jquery_ui_add(array('ui.datepicker'));
	else
		jquery_ui_add(array('ui.draggable', 'ui.datepicker'));

Happy drupaling!

Thanks to Wei Wang, who tipped me off: http://groups.google.com/group/jquery-ui/browse_thread/thread/675b5fbb64ee7664

Text-version of the error for the Google machine:

$.widget is not a function

http://xxx.com/yyy/zzz/ui.draggable.js?6

Line 391

Update

After writing up this post, I realized that the first option is really not that tough. (Note that if you follow these steps, you’ll have to repeat them every time you update the Devel module.) Add the following line to the Devel Themer module’s devel.info:

dependencies[] = jquery_ui

Now, find the ‘devel_themer_init()’ function in devel_themer.module, and comment out the following lines (104 and 105 for the current version):

    drupal_add_js($path .'/ui.mouse.js');
    drupal_add_js($path .'/ui.draggable.js');

Immediately following the newly commented out lines, insert the following:

	jquery_ui_add(array('ui.draggable', 'ui.mouse'));

You’re done! Booyah.

→ 5 CommentsTags: Uncategorized

Removing symbolic links to directories

April 13th, 2009 · 1 Comment

Having trouble removing a symlink from your POSIX compliant (Linux/Unix/OSX/MyDogSamix) system?  A quick Google yields some interesting results, which may or may not be helpful.

Most likely, you’ll find a bunch of condescending links highlighting the fact that you can just ‘rm <symlink>’ the symbolic link.  Silly newb. However, if this is a directory, you might have problems.

The most important thing to remember is that to remove a symlink that points to a directory, you must not include the trailing slash.

In other words:

[fdev@warproof sites]$ ls ../sites/
all  default  sites
[fdev@warproof sites]$ rm sites/
rm: cannot remove `sites/': Not a directory
[fdev@warproof sites]$ rm sites
[fdev@warproof sites]$ ls
all  default

Notice that the first attempt (‘rm sites/’) failed, while the second attempt (‘rm sites’) did not. YMMV, but in this case, I blame my autocompletion (aka tab completion) – it automatically adds the trailing slash. Remove that slash, and you’ll remove the symlink.

May all your deletions be error-free.

→ 1 CommentTags: Uncategorized

Flex vs CS3 – Filesize concerns (aka Flex SWFs are huge!)

March 18th, 2009 · 1 Comment

For a while now, I’ve been using FlashDevelop and CS3 exclusively for all of my AS3 development.  However, as my project became more and more complex, CS3 crashes became more frequent.  A few days ago, in fact, CS3 was crashing on every single compilation.  Very strange.

So, I looked into migrating my compilation to the Flex SDK.  After I got everything working, I noticed that my AS3-only (no imported Flex components) file sizes were much larger than those produced by CS3, even when compiled in FlashDevelop’s ‘Release’ mode.

After some tinkering, I discovered that the ‘verbose-stacktraces’ option increases filesize considerably.  If you’re frustrated with large filesizes, ensure that you’re actually compiling with ‘debug’ and ‘verbose-stacktraces’ both set to ‘false’ (or removing the parameters entirely).

(In FlashDevelop, change to ‘Release’ mode using the dropdown on the main toolbar, and turn off ‘verbose-stacktraces’ at Project -> Properties -> Compiler Options -> Verbose Stack Traces. Also, on the same screen, make sure ‘Optimize Bytecode’ is set to ‘True’.)

The Bottom Line

Bad

mxmlc -load-config+=obj\FeaturificSlimConfig.xml -debug=true -incremental=true -optimize=true -verbose-stacktraces=true  -o obj\FeaturificSlim633729054843281250

Good

mxmlc -load-config+=obj\FeaturificSlimConfig.xml -incremental=true -optimize=true -o obj\FeaturificSlim633729054843281250

→ 1 CommentTags: Uncategorized

Make JQuery and Prototype Love Each Other

July 10th, 2008 · 11 Comments

Hello Googlers – Are you getting the following mind-boggling error on your web app as well?

Here it is in its expanded form within Firebug:

‘Security error” code: “1000′ ? Real helpful, prototype. Thanks.

So, first of all, it will likely take you a very long time to realize that these errors stem from an incompatibility between JQuery and Prototype. Then, it will probabaly take you even longer to find out why this is the case and devise a workaround.

Well, in the interest of saving you loads of time, here’s what’s going on.

JQuery and Prototype both use the ‘$’ function (yes, the dollar sign) extensively. Unfortunately, each framework defines the $ function differently. Also, only one definition for the dollar sign function can exist at a time. So, either JQuery is happy or Prototype is happy but never both simultaneously.

If you’re trying to use JQuery and Prototype at the same time, you might get an error like the one shown above. Or, you might get an error that’s completely different, given certain variables (e.g. which library was loaded first).

The Solution

The solution is easy. The JQuery guys will tell you exactly what you need to do! In our particular scenario, none of the proposed solutions would work. So, we simply edited prototype.js (and scriptaculous.js, effects.js, lightwindow.js, etc) so that instead of calling ‘$()’, they now call ‘$p()’. This allows our JQuery code to execute flawlessly without modification while still allowing Prototype to function in parallel.

Hope something here helps you get rid of Prototype’s worthless error message too!

Text versions of the error message to aid in search engine indexing:

Short version:
Security error” code: “1000

http://www.qgia.com/qgia/lightwindow/javascript/prototype.js

Line 1264
Long version:
Security error” code: “1000
(no name)()common.js.pkg.php (line 271)
(no name)(“Uncaught exception in hook (`onloadhooks’) #0: LinkController is not defined [at line 400 in http://…”, “error”)common.js.pkg.php (line 271)
(no name)()common.js.pkg.php (line 269)
_runHooks(undefined)common.js.pkg.php (line 152)
_onloadHook()common.js.pkg.php (line 148)
(no name)()common.js.pkg.php (line 155)
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

→ 11 CommentsTags: Uncategorized

WordPress on OS X Tiger – “error establishing a database connection”

May 31st, 2008 · No Comments

Installing WordPress on OS X Tiger and getting the ambiguous ”error establishing a database connection” error?  Fixing this problem was easy for me, once I knew what to do.

The problem is with your php.ini file.  The default socket value is initially blank:

mysql.default_socket =

To get WordPress to work, you need to set a default socket.  Values that have worked in some situations include:

mysql.default_socket = /private/tmp/mysql.sock

mysql.default_socket = /tmp/mysql.sock

In my particular situation (default MySQL and Apache installs on Tiger), I had to use the following socket:

mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock

For info on locating and modifying your php.ini file, see the Bust Out Solutions blog.

→ No CommentsTags: Uncategorized

Internet Explorer cannot open the Internet site, Operation aborted

May 23rd, 2008 · No Comments

Just a bit of Google-fodder here. One of my Drupal-based sites started generating weird errors in IE recently. “Internet Explorer cannot open the Internet site, Operation aborted”. Whaaa? The error prevented the page from loading and made the page unusable. Lame. Don’t we love IE?

Anyway, I thought I’d add my solution to the hive.  Inspired by reports of conflicting javascripts (notably SWFObject) causing this problem, I realized that the problem started occurring near to the time at which I enabled the “Lightbox” Drupal module.  I disabled the module and everything worked like a charm.  Using defer=”defer” didn’t work reliably since SWFObject does, in fact, write to the body.

For now, this works.  However, it’s not a good long term solution… Any thoughts on how to get SWFObject and Lightbox to play nicely together?

 

→ No CommentsTags: Uncategorized

scRUBYt! and WWW::Mechanize foiled (aka Sneaky Yahoo Scraping Prevention)

April 15th, 2008 · 3 Comments

Screen scraping. It’s one of those techniques that can be loads of fun and also heaps of frustration. On a recent project, I was charged with scraping some pages from Yahoo! Shopping.

I Hate Screen Scraping

After coding up a quick skeleton, I was surprised to see that none of my initial tests were working – it was almost as if the data wasn’t even there. Checking out the rendered page in Firefox revealed the problem – none of the links I needed to scrape were present. At all. So, I hit up the Yahoo source code to verify that the links were in the original. Yup, right there. Weird!

I tried out a variety of my favorite scraping tools – scRUBYt!, WWW::Mechanize, and even good ol’ cURL. None of these tools could acquire HTML source from the Yahoo server with links intact, even when I provided a valid Firefox User-Agent string.

Next, I dropped down to an even lower level – packet sniffing with my favorite sniffer, Packetyzer, and sending HTTP 1.1 requests directly via telnet.

rich@redbuntu:~$ telnet shopping.yahoo.com 80
Trying 209.73.163.95...
Connected to pdb3.shop.yahoo.akadns.net.
Escape character is '^]'.
GET / HTTP/1.1
Host:shopping.yahoo.com
 
HTTP/1.1 200 OK
Date: Tue, 15 Apr 2008 17:48:16 GMT
P3P: policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
Cache-Control: private
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
 
a17e
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
etc...

Three interesting things jumped out at me when I executed this request. FIrst, I didn’t recognize the P3P header – turns out this is just a compact privacy policy, so no dice there. Second, I noticed the absence of the Server header, which is usually used to identify the server’s software, version, installed modules, etc. Since Yahoo opted to hide this line, it seems increasingly possible that Yahoo is ‘gaming’ us. (And a only shows that they’re running FreeBSD with an unidentified web server) Third, I noticed that the response was being sent uncompressed. This made sense since I did not specify in my HTTP 1.1 request that my ‘client’ (telnet) supported compression. However, while sniffing packets earlier, I noticed that all of the HTTP responses were compressed. (Edit: Another interesting feature – “a17e”. What in the world is this?)

Those Sneaky Geeks

It sounded crazy, but I realized that Yahoo could be using clients’ compression support to differentiate between bots and actual web browsers. So, I popped open another terminal and tried making a request as I did before with cURL, except with a Firefox User-Agent string and compression enabled.

curl --user-agent "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.5) Gecko/20070713 FireFox/2.0.0.5" --compressed "http://shopping.yahoo.com/path/to/resource" > result.html

Bingo! All of the links were intact – the source was identical to that which a standard web browser would retrieve. So, it seems that Yahoo has written some sort of Apache module or perhaps just engineered their application code to vary its response according to whether or not the client supports compression. This is quite a sneaky way to deter search engine indexing and screen scraping in general, but it works wonderfully. In fact, if I were the engineer that devised this detection method, I’d be pretty pround of myself. Unfortunately, now that we know Yahoo’s secret, our scraping workflow just gets one more step: curl > result.html.

→ 3 CommentsTags: Uncategorized