jQuery selecting the next N siblings

by Jason on

Problem: you have a large set of tags and need to get the next 50 out of the set.

To do this I would in the past use: $(‘li’).nextAll().slice(0,50) Or $(‘li’).nextAll(‘*:lt(50)’)

However on a very large set of tags (> 20,000) nextAll can cause script timeout warnings / errors. (This makes sense as you are getting the entire set, storing it in a jQuery object and then filtering it.)

Here’s a tiny jQuery plugin that provides “nextN”:


  • nextN jQuery Plugin *
  • usage: $(‘li’).nextN(50)
  • returns the top 50 elements that match the parent selector / (function($) { $.fn.extend({

    nextN: function(nextN_limit){
    			    var nextN_els = this;
    			    //loop until limit
    			    for(var i=1;i<nextN_limit;i++){
    			       //add next sibling after last if it exists
    			       if($(nextN_els).filter(':last').next().length > 0){
    			            nextN_els = $(nextN_els).add($(nextN_els).filter(':last').next());
    			    //return modified jquery object
    			    return nextN_els;

    }) })(jQuery);

Note: unlike “nextAll” and “next” this plugin returns the parent as well.

How common a problem is this? Probably pretty rare. In most instances $(‘li’).nextAll(‘*:lt(50)’) would be appropriate.

Requiring elevated UAC permissions in C#

by Jason on

More of a note to myself than anything else but perhaps it would be handy for others…

2 Solutions:

Throw the UAC prompt when a user tries to execute your application:

To enforce UAC rules on your C# application add the appropriate param in your application manifest file:

Add the Application Manifest:

Add New Item to your project, under C# items, Application Manifest File.

Open your manifest, under “requestedExecutionLevel” change the level param to “requireAdministrator” and voila, your application will now throw a UAC prompt before executing.

Note: using Visual Studio 2008

Run the app regardless and bail when incorrect permissions are found

If you’d like you users to just right click / run as administrator and not worry about UAC add the following to your Main sub or application entry point:

add this method to you application:

public static bool checkAdminPrivileges(){
			    WindowsIdentity i = WindowsIdentity.GetCurrent();
			    WindowsPrincipal p = new WindowsPrincipal(i);
			    return p.IsInRole(WindowsBuiltInRole.Administrator);

Call that method and take appropriate action:

if (!checkAdminPrivileges())
			        Console.Error.WriteLine("Access Denied. Administrator permissions needed");
			        //do something here, exit, die

Moving Day

by Jason on

Moving this over from vfoo.wordpress.com and hope to create a bit more here.

Firefox and username vulnerability followup

by Jason on

Due to the inherent ambiguities in form-based logins, there’s an unavoidable tradeoff here between making the password manager work on lots of sites, and having it match the behavior of the old FF2 password manager (which checked field names). We’ve chosen to go with better functionality in the new password manager.

From: https://bugzilla.mozilla.org/show_bug.cgi?id=499223
This is kinda funny actually. The vast majority of sites field names for username and password do not change, or only change when there is a redesign. This thought process assumes that sites might constantly switch field names or form names or other basic tag attributes to confuse just who now?

Love Firefox but this decision (RESOLVED WONTFIX) irks me. Now I’ll have to turn autocomplete off on any plain text field followed by a password type field just to cater to Firefox’s overzealous credential remembering scheme.

Need to file a new feature request: Please let FF3 alert me when it’s using stored credentials (infobar type thing maybe) because maybe the user can’t see the field that’s now submitting my username and password to the world.

On another note, this seems like an easy way to gain login credentials of people using sites that allow for code import / widget creation, ugh.