Category: Programming (page 2)

12 Feb 2013

Shared Server Development with PhpStorm

Working on a remote server—with or without multiple developers—is just asking for problems, but sometimes there’s no way around this. I’ve used several IDEs for this task and found that PhpStorm has several unique features that ease the pain considerably: It fingerprints remote content on download and re-verifies the remote content before auto-uploading. If someone else has edited

[ the post]
4 Dec 2012

Designing a Highly Reusable HTML Component

The UF College of Education uses a header/footer template designed to be applied to any page, and we use this across several applications such as WordPress, Moodle, Elgg, and Drupal. Changes can be propagated quickly to all sites, and adding the template to new PHP apps is trivial. If you need to create an HTML component that can be

[ the post]
27 Aug 2012

Decouple User and App State From the Session

When building software components, you want them to be usable in any situation, and especially inside other web apps. The user of your component should be able to inject the user ID and other app state without side effects, and similarly be able to pull that state out after use. That’s why, beyond all the standard

[ the post]
25 Aug 2012

Elgg Plugin Tip: Make Your Display Queries Extensible With Plugin Hooks

If you’re building an Elgg plugin that executes queries to fetch entities/annotations/etc. for display, odds are someone else will one day need to alter your query, e.g. to change the LIMIT or ORDER BY clauses. Depending on where your query occurs, he/she may have to override a view, replace an action, replace a whole page

[ the post]
17 Aug 2012

My Moodle Page, Now With 99.6% Fewer Queries

My work recently upgraded from Moodle 1.9 to 2.3, and some users were experiencing slow page loads while the site was zippy for others. Today we discovered that, for some users, the My Moodle dashboard page was requiring several thousands of DB queries. For one user, enrolled in four courses, the page required over 14,000 queries.

[ the post]
23 Jul 2012

In Support of Bloated, Heavyweight IDEs

I’ve done plenty of programming in bare-bones text editors of all kinds over the years. Free/open editors were once pretty bad and a lot of capable commercial ones have been expensive. Today it’s still handy to pop a change into Github’s web editor or nano. Frankly, though, I’m unconvinced by arguments suggesting I use text editors

[ the post]
16 Apr 2012

Define namespace constants using expressions

Since const is parsed at compile-time, you can’t use expressions in namespace constants, but you can use define as long as the name argument is the full name from the global scope (run this): namespace Foo\Bar; const CONST1 = 1; define(‘CONST2′, 1 + 1); // global define(__NAMESPACE__ . ‘\\CONST3′, 1 + 1 + 1); //

[ the post]
15 Apr 2012

PHP RFC Preview: Dynamic Callback Expressions

I’m posting this to get some initial feedback on this idea before I officially submit an RFC. Background Even with PHP’s growing object-oriented and functional programming features, the callback remains widely-used and useful. However, forcing authors to create callbacks via strings and arrays presents difficulties: Most IDEs do not recognize callbacks as such, and so

[ the post]
22 Jan 2012

Convert Google Maps embed HTML to Street View URL

You can use the form below to convert the HTML embed code Google Maps gives you to a usable Street View URL loading… Why do I need this? The new Google Maps layout has a chain-link icon on the left that gives you a URL to what you’re looking at. If you’re in Street View, sometimes

[ the post]
25 Dec 2011

ElggCollection Proposal

An ElggCollection entity would store an ordered set of integers optimized for filtering and/or ordering SQL queries of entities, annotations, or other tables with integer primary keys.

[ the post]
28 Sep 2011

String Subtypes for Safer Web Programming

Valid HTML markup involves several different contexts and escaping rules, yet many APIs give no precise indication of which context their string return values are escaped for, or how strings should be escaped before being passed in (let’s not even get into character encoding). Most programming languages only have a single String type, so there’s

[ the post]
15 Sep 2011

RotURL: Rot13 for URLs

RotURL is a simple substitution cipher for encoding/obscuring URLs embedded in other URLs (e.g. in a querystring). Also, common chars that need to be escaped (:/?=&%#) are mapped to infrequently used capital letters, so this generally yields shorter querystrings, too. /**  * Rot35 with URL/urlencode-friendly mappings. To avoid increasing size during * urlencode(), commonly encoded

[ the post]
13 Sep 2011

Validate Private Page Bookmarklet

ValidatePrivatePage <– validates in current window ValidatePrivatePage <– validates in new window (your pop-up blocker may complain) If you need to validate the markup of a page that’s not public (e.g. on localhost), you can now use this bookmarklet to auto-submit the current page source to the validator (instead of viewing source, copying, opening the

[ the post]
18 Aug 2011

NetBeans Love & Hate

For those cases where you have to work on remote code, NetBeans‘ remote project functionality seems to put it ahead of other PHP IDEs. It pulls down a tree of files and uploads files that you save. Having a local copy allows it to offer its full code comprehension, auto-complete, and great rename refactoring for “remote”

[ the post]
18 Jul 2011

Helping Netbeans/PhpStorm with Autocomplete/Code-hinting

Where Netbeans can’t guess the type/existence of a local variable, you can tell it in a multiline comment: /* @var $varName TypeName */ After this comment (and as long as TypeName is defined in your project/project’s include path), when you start to type $varName, Netbeans will offer to autocomplete it, and will offer TypeName method/property suggestions.

[ the post]
3 Jul 2011

Firefox 5 Shibboleth Issues

If you manage a Shibboleth SP and have been receiving complaints from Firefox 5 users, you may be running into an issue due to FF5’s more compliant caching of Location headers in 302 redirects. While this is a step in the right direction for front-end performance, even tiny HTTP handling changes can affect existing sites.

[ the post]
21 Jun 2011

Bookmarklet: Horizontally invert HTML5 videos

My demands for “reverse” glasses have gone unserved, but I made a bookmarklet that provides the same effect: “flopping” a video horizontally. Install the SwitchStance bookmarklet, for which you’ll need a modern browser that supports CSS transforms on video elements. Opt-in to YouTube’s HTML5 trial Load up any video without ads (here’s one of Matt

[ the post]
29 Apr 2011

ReCaptcha Broken? Here’s the fix

Sometime recently ReCaptcha decommissioned its old API hosts: api* The new API locations are at “http(s)://”. If you rely on Zend_Service_ReCaptcha (or its form element), you’ll need to change some constants in Zend/Service/ReCaptcha.php:

[ the post]
22 Apr 2011

Xdebug 2.1.1 for XAMPP OSX 1.7.3

xdebug-211-xampp-osx.tgz contains a freshly compiled xdebug 2.1.1 module for XAMPP OSX, using this tutorial as a guide. The archive contains step-by-step install instructions w/ bash commands. Happy debugging with fewer bugs.

[ the post]
22 Apr 2011

Bash: Resolve symlinks in your working directory

Say you have created a symlink from your home dir to another location: $ ln -s /Applications/XAMPP/xamppfiles/htdocs ~/htdocs Now you can easily change to the XAMPP htdocs: cd ~/htdocs and then get back home: cd .. But how do you get to xamppfiles? Update: Thanks to sapphirepaw, the solution is simple: cd -P htdocs/.. or

[ the post]