Archive for the ‘Development’ Category

My first Scout plugin!

September 8th, 2013 No comments

I'm digging Scout so far, and it has almost all the plugins I would want already in their plugin directory. However, I did want to add in a Solr "healthcheck", since we've noticed some oddities with our search index.

Here is a quick-and-dirty way to get the number of results based on an empty search (i.e. the entire index) for a single Solr core on localhost. Maybe this will help somebody else out there. I suppose it could be paramterized with hostnames, search strings, etc... and it wouldn't be that hard either from what it looks like.


Filename: solr.rb

class SolrResultCount < Scout::Plugin

  needs "rubygems"
  needs "json"
  needs "net/http"

  def build_report
    url = "http://localhost:8983/solr/select?q=&rows=3&fl=bundle&wt=json"
    r = Net::HTTP.get_response(URI.parse(url))
    parsed = JSON.parse(r.body)

Categories: Development

United States of Google

January 23rd, 2011 No comments

Just saw this code on a site, I forgot this good stuff existed. I've seen it before in a post about Google's web fonts and using their jsapi to load the webfont.js file, and I just rediscovered it again. I love Google. Using their clout to better the web (IMHO.) You can call me a fanboy - I don't care.

<script type="text/javascript" src=""></script>
<script type="text/javascript">google.load("jquery", "1.4");</script>
<script type="text/javascript">google.load("jqueryui", "1.7.2");</script>
Categories: Development

True "Incognito" mode for Google chrome

January 8th, 2011 No comments

I hate Windows. I do.

This is a very hacky, no-garbage-collection, but still "working good enough" script. At the advice of #chromium on freenode, when asked about cookie sharing between Incognito windows, I was told it's been discussed before, and I got the information on how to make sure that your Incognito windows don't share information or cookies by forcing separate user data directories.

I'm not really worried about privacy, I'm more annoyed that I launch separate Incognito windows and it shares cookies between them, which is sort of against the point. I have to login to the same sites over and over under different accounts for different clients, and it's a PITA.

Major things to note:

  • This assumes you'll run some sort of "temp directory cleanup" tool on your own for Windows. This doesn't have any concept of "oh yeah, I have to cleanup that temp directory I made"
  • None of your extensions, bookmarks, settings, etc. will be remembered in this session. It's completely barren.
  • You will never (assuming the GUID is unique) get the same session more than once.

As I said, it's hacky, and you'll need to change a couple of the paths. I couldn't figure it out elegantly, and I was getting tired of trying to find script examples on the net (why is it so hard to find code that works together for Microsoft languages?)

Perhaps someday soon Chrome or someone will develop something more robust for this. For now, if you want - this does seem to work, at least on my XP SP3 system.

Note: This is vbscript. Make a file called "incognito.vbs" or something and it should work.

' keep us honest
Option Explicit

' because we have to
Dim strDirectory
Dim strTempDirectory
Dim TypeLib
Dim objFSO
Dim objShell
Dim strChromePath

' change this if you want - anything with spaces has to have be wrapped in triple quotes
strChromePath = """C:\Documents and Settings\mike\Local Settings\Application Data\Google\Chrome\Application\chrome.exe"""
strTempDirectory = "C:\Windows\Temp"

' make a clean guid
Set TypeLib = CreateObject("Scriptlet.TypeLib")
strDirectory = TypeLib.Guid
strDirectory = Replace(strDirectory, "{", "")
strDirectory = Replace(strDirectory, "}", "")
strDirectory = strTempDirectory & "\" & strDirectory

' create the directory
Set objFSO = CreateObject("Scripting.FileSystemObject")

' launch it, or fail
If err.number = vbEmpty then
   Set objShell = CreateObject("WScript.Shell") (strChromePath & " --incognito --no-first-run --user-data-dir=" & strDirectory)
   WScript.echo "VBScript Error: " & err.number
End If

' cleanup
Set TypeLib = nothing
set objFSO = nothing
Set objShell = nothing

' quit
Categories: Development, Software

Pidoco - rapid prototyping/wireframing - why didn't I find this before?

November 11th, 2010 No comments

A while ago, I was looking for tools to do prototyping/wireframing so I could explain my ideas a bit better than some crappy sketched out "wireframes" on paper. For some reason, this one did not come up, so I want to help them gain exposure for being so awesome.

I just discovered this tool in the last hour. It not only  allows you to make wireframes, but actually usable prototypes - with links to external sites and other pages inside of the prototype, pull in external images and content, has layers like photoshop ... the list goes on and on. Best part is the learning curve was quite simple. I found another tool which was an Adobe AIR-based app, if I recall, but it was a bit cryptic and hard to use. This thing allows you to even invite people to do usability testing on your prototype, record their movements, leave comments, etc. Best of all, the cost is extremely reasonable!

There's simply too much to name off and now all I want to do for the next month is prototype out all my ideas!

Categories: Development, Software

How would I change PHP?

September 22nd, 2010 3 comments

Anyone who knows me knows I am a PHP fanboy. I use PHP for everything - web applications, web scraping, batch scripting, if there is an itch that software can fix, I try to scratch it with PHP. I dreamed of a PHP scripting plugin for Eggdrop IRC bots, so I didn't have to fuss with TCL. Anywhere PHP could be adopted, I've hoped someone was working on a way it could be.

However, if you talk to people who know the internals of PHP they'll tell you there's a lot of ugly stuff in there. That it's a language based on macros, etc. I don't necessarily care about that. My experience is from a user perspective, not an internals one. That being said, just from my higher level interaction with the language, these are some of the things I'd love to change.

  • Make function name conventions consistent. Some functions have underscores, some don't. strpos vs. str_replace, html_entity_decode vs. htmlentities, etc.
  • Make argument order consistent for similar types of functions. Depending on what you're doing, it's one or the other. in_array($needle, $haystack) vs. strstr($haystack, $needle), etc.
  • Optimize the core. Strip the core down more, and push more things into modules. Enable some of them by default, fine. But when it comes down to it, I don't need easily 30-40% of the functions that PHP has built in.
  • Combine similar functions and use arguments to define the behavior. For example addslashes() and addcslashes(). Make it one function with a constant to define its behavior.
  • Disable magic quotes (preferred) or enable it and don't give any option to change it. As far as I'm concerned as long as you pick one route, you can guarantee universal compatibility, whether that means using magic quotes, or not using them and expecting developers to understand input sanitization, sanity checking/type checking/all that jazz. Which I don't think is a bad thing.
  • Implement a "strict" mode. "PHP is lazy" as Rasmus says which is fine and all, but I don't like the PHP name shamed with terms like "insecure" - any code can be insecure in any language, however, PHP is so easy to pick up and get things going that it makes it too easy to write crappy and insecure code. Specifics on a "strict mode"? I've got none. It's late and I can't think of how I would enforce better coding practices in core...
  • Get rid of $_REQUEST. I've advocated this for years and even unset($_REQUEST) in my code. To me it's a lazy person's workaround for coding and introduces some of the same vectors that were closed when disabling register_globals. If you -really- want to have a $_REQUEST type mechanism in your code, just array_merge($_GET, $_POST, $_COOKIE, etc) in whatever oder you want. I dislike using software that uses $_REQUEST by default but doesn't actually need the flexibility of POST vs. GET vs. COOKIE and such. Know which input stream your data is coming from, if nothing else, it will at least make replay attacks and such much harder for people to craft.
  • Get rid of objects and OO stuff. Yeah, I said it. Everyone loves OOP. Why? While I see the power of being able to extend classes, I also see it seeming to be the most troublesome when it comes to compatibility checks, all the APC crashing or odd bugs I've suffered from were due to it. If you look at something like Drupal, they've figured out how to extend or override using procedural code quite well. Sadly, even they're converting more things to OO as well.  IMO, OOP is more suited for longer-running applications, perhaps something event driven where a new object to represent a connection is created (however, C's been doing this without dealing with objects forever, it doesn't HAVE to be OO...) Those are the two main examples I see for using OO. Disclaimer: I wasn't raised in an OO environment, this is all based on personal experience and preference. 🙂

I've memorized the function list for what I use pretty well (like I said, I probably only use a subset of the functions in PHP) however the most annoying thing is when it comes to the needle vs. haystack argument positioning. I usually have to reference for it. Sometimes I can trial and error though. In an ideal world, I wouldn't have to.

It would be great if something like PHP 6.0 would adopt some of these practices, since it is a major version change. Perl, Ruby and Python I believe have all done similar things where a major change really was a dramatic change and required conversion of code to meet its new requirements.

I'm sure this list could grow, and I may add to it. Who knows.

Categories: Development, PHP

Little-known URI shorthand - the "network-path" reference

July 21st, 2010 No comments

I've seen this before, and it was mentioned earlier today at OSCON, but I never knew if it was a browser behavior or a standard. Looks like I got it with some help from IRC.

Say you have a foreign host and you don't want to have to figure out if you're on http:// or https:// and call their assets appropriately so you don't get a mixed-mode warning. You can actually use a syntax that is defined in RFC 3986, specifically section 4.2:

A relative reference that begins with two slash characters is termed a network-path reference; such references are rarely used. A relative reference that begins with a single slash character is termed an absolute-path reference. A relative reference that does not begin with a slash character is termed a relative-path reference.

Which means you can do this:

<img src="//" />

and your browser will request or, depending on what scheme your browser is currently on.

I was hesitant at first to consider it "okay" but as it is published in the RFC and Chromium's fixed bugs relating to it, it does appear to be a properly supported method that could save you a few keystrokes. Let me know if it doesn't work for you! Be sure to give browser/OS information and conditions to reproduce.

Oh yeah, and the other host needs to be on https as well, of course. I shouldn't really have to say that, though 🙂

Categories: Development

PHP-FPM and nginx upstart scripts

May 21st, 2010 4 comments

Upstart is becoming the de-facto standard for everything in Ubuntu, and I do enjoy it's process management and re-spawning capabilities.

(Actually, before PHP-FPM I used to use upstart jobs to su - $user php-cgi -b $port :))

These are VERY simple but effective scripts, and would actually be beefed up to be more intelligent (chaining nginx to start after PHP-FPM for example. However, if you do not need PHP, then that's a useless chain. So I kept it simple. I suppose you could add a short delay to start nginx then...)

Note: make sure PHP-FPM is set to daemonized = yes.

Second note: this works for PHP 5.2.x w/ the PHP-FPM patch, on Ubuntu Lucid Lynx (10.04) - anything else YMMV. I am not using PHP-FPM w/ PHP 5.3 yet since I have no environments that I know will support 5.3 code. When I finally get one, I will look for the same opportunity.


description "nginx"

start on (net-device-up and local-filesystems)
stop on runlevel [016]

expect fork
exec /usr/sbin/nginx


description "PHP FastCGI Process Manager"

start on (net-device-up and local-filesystems)
stop on runlevel [016]

expect fork
exec /usr/local/bin/php-cgi --fpm --fpm-config /etc/php-fpm.conf

Once you've done this you can remove all the /etc/init.d/php-fpm, /etc/init.d/nginx and /etc/rc?.d/[K,S]??php-fpm and /etc/rc?.d/[K,S]??nginx symlinks and files. This takes care of all of that.

Feel free to comment and leave better tips, tricks and ideas!

Categories: Development, nginx, PHP, PHP-FPM

Getting Capistrano's SSH method to work behind a SOCKS proxy

April 30th, 2010 No comments

At work we've got a bit of an annoying proxy setup. It does allow outbound SSH through a SOCKS 5 proxy (no auth), and after a while of Googling (I don't know Capistrano nor Ruby, but the Ruby app developer did) we were able to figure it out.

Assuming you have the Net::SSH::Proxy::SOCKS5 class installed on your system (which may come as part of net-ssh?) it's actually quite simple. Getting the ssh settings right took a while of looking around, but it wound up being quite easy, and since I could not find anything on the net about this, I wanted to post our findings.

It's as simple as adding the following to the applications's config/deploy.rb:

require 'net/ssh/proxy/socks5'

sshproxy ='', 1080)
set :ssh_options, { :proxy => sshproxy }


Obviously there are more options, but we had a hell of a time trying to correlate the options and get them fed into the SSH module (if that's the right term) properly. It'd probably be much simpler if I had known Ruby, or if this problem was in PHP 🙂 Anyway, I try to share what I can when I get it... (this post is only over four months overdue...)


Categories: Development


April 19th, 2010 No comments

Google's usually pretty good about pushing standards and best practices but this is just lame.

From my understanding, if you type in in your browser it will now remove the http:// - not that it matters, the browser auto-prepends if it you leave it out, but it's not intuitive at all now, and it's not like it was a change that needed to be done.

This is just going to make more people copy/paste the wrong URLs into pages, not get autolinked properly, etc. How many <a href=""> type links will there be if this starts spreading... I like being able to copy/paste directly from the address bar.

I don't care if people don't put it in when you type in "" - the issue here is the output and reuse and the general idea of "this is a legitimate URL" - considering the RFC for URLs does maintain that you need a scheme!

"A URL contains the name of the scheme being used (<scheme>) followed by a colon and then a string (the <scheme-specific-part>) whose interpretation depends on the scheme."

Categories: Development, Software

The UK's got it right - government-collected data access for free

January 21st, 2010 3 comments

"A new website,, will offer reams of public sector data, ranging from traffic statistics to crime figures, for private or commercial use.

The target is to kickstart a new wave of services that find novel ways to make use of the information."

Awesome. I had an idea like this for a while back - generic data being available for consumption, but I really don't have any origin feeds that aren't already exposed. I'd just be re-syndicating them. But this would be awesome to have, just think of all the mashups you could create depending on what data is exposed.


Categories: Consumerism, Development