jQuery Change Persister for DOM text inputs

/*
 jQuery tbChangePersister v1.0.0 - April 2015
 by Nick Kewney
 */
(function ($) {
    $.fn.tbChangePersister = function (next, defaultDelay, domStorageSuffix) {
        return this.each(function () {
            var timer = 0,
                that = $(this),
                delay = defaultDelay || 5000;
            that.keyup(function () {
                clearTimeout(timer);
                var context = that.val();
                if (localStorage) {
                    localStorage.setItem("tbChangePersisterValue-" + domStorageSuffix, context);
                }
                timer = setTimeout(function() {
                    next();
                }, delay);
            });
        });
    };
})(jQuery);

Example usage:

$("#myElement").tbChangePersister(function () {
            var d = new Date();
            var time = d.toLocaleTimeString();
            $("#myElementMessage").text("Draft autosaved " + time);
        }, 500, "myStorageName");

Set the value:

if (localStorage) {
            var content = localStorage.getItem("myStorageName");
            if (content) {
                $("#myElement").text(content);
            }
        }

 

Extracting a price from a VARCHAR in T-SQL

CREATE FUNCTION [dbo].[fn_extract_currency_from_string] (@string VARCHAR(1000))
RETURNS VARCHAR(255)
AS
BEGIN

	DECLARE @var VARCHAR(1000) = @string
	DECLARE @len INT = LEN(@var)

	DECLARE @start_position INT
		,@end_position INT

	DECLARE @temp_string VARCHAR(100)

	SELECT @start_position = PATINDEX('%£%', @var)

	SELECT @temp_string = SUBSTRING(@var, @start_position + 1, @len)

	SELECT @end_position = PATINDEX('% %', @temp_string)

	-- Done
	RETURN substring(@temp_string, 1, CASE @end_position WHEN 0 THEN @len ELSE @end_position -1 END)
END

 

Web Application Security Testing Tools

Port Scanners

  • Nmap – general port scanner

 Vulnerability Scanners

  • Nikto and Wikto – web server vulnerability checkers
  • Nessus – general purpose vulnerability checker
  • WebInspect – web application vulnerability scanner
  • Absinthe – SQL injection testing tool

Information Gathering Tools

  • SpiderFoot – footprinting tool
  • wget – site duplication tool
  • Offline Explorer – site duplication tool
  • WinHTTrack – site mirroring tool

Web Proxy Tools

  • Paros – local proxy and data manipulation tool
  • Spike proxy – proxy and data manipulation tool
  • Fiddler – proxy and data manipulation tool
  • Web View / Syntax View / Timeline – Fiddler extension
  • Burp Suite – proxy and data manipulation tool
  • POSTHook – IE plugin to manipulate POST data
  • TamperIE – IE plugin to manipulate GET and POST data
  • Webproxy – proxy and data manipulation tool
  • Webscarab – proxy and data manipulation tool

Browser Tools

  • IE, Chrome, Firefox, Opera – browsers
  • Mozilla Web Developer Toolbar – browser tool
  • IE Developer Toolbar – browser tool
  • Mozilla IE Tab Plugin – browser tool
  • Firefox Tools
  • HackBar – encoders/decoders
  • Web Developer Toolbar – modify objects in web pages
  • Tamper Data – manipulate HTTP data and headers
  • Firebug – modify HTML, Java, and CSS in the browser
  • Grease Monkey – add user defined JavaScript to a web page
  • Switch Proxy – allows easy switching of web proxies
  • FoxyProxy – regex based smart proxy selector
  • Edit Cookies – cookie editor
  • XSS-Me – cross site scripting tool
  • SQL Inject Me – SQL injection testing tool
  • CookieSwap – cookie editor
  • RoboForm – caching form data for testing

Cookies / Session Manipulation Tools

  • Cookie Pal – Cookie capture and viewing tool
  • CookieSpy – Cookie manipulation plugin for IE
  • IESpy – Cookie manipulation plugin for IE

HTTP Request Generation Tools

  • netcat – raw packet generation tool
  • wfetch – raw HTTP request generation tool

SSL Proxy Tools

  • openssl – SSL programming toolkit
  • stunnel – SSL proxy tool

Password Guessing Tools

  • Brutus – multi-purpose password brute forcer
  • Webcracker – HTTP authentication brute forcer
  • Hydra – Brute force password guessing tool for HTTP, FTP, etc

Decompiles

  • JAD/Jode – Java decompiler
  • Reflector – .NET decompiler
  • Reflexil – Add-in for Reflector used to modify decompiled .NET code
  • FileDisassembler – Add-in for Reflector to export .NET code to Visual Studio

Miscellaneous

  • fpipe – traffic redirector
  • lynx – text browser
  • curl – web client tool
  • Dave Proxy – proxy tool used for thick client applications
  • Dave – WebDAV tool
  • Cadaver – WebDAV tool
  • SSLDigger – SSL cipher strength checker
  • THCSSLCheck – SSL cipher strength checker
  • Perl, Python – coding tools for custom scripts
  • Twill – scripting language for web browsing

Virgin Money London Marathon 2015

I will be running the 2015 Virgin Money London Marathon on 26th April 2015 for the British Lung Foundation who are currently funding research on the prevention of lung damage in COPD and many other areas related to lung disease.  You can read more about the BLF’s research here.

My fundraising target this year is £1,750.00 and any donations, big or small, would be greatly appreciated.  My fundraising page can be found here.

If you leave your name on the donation list, I’ll be sure to contact you to say thanks 🙂

Arduino Christmas Tree Project

I decided that it was essential to give our customers the ability to turn our Christmas tree lights on and off over the web.

treeapi

Check out our Christmas Tree API here, Arduino code below.  Live stream to follow!

IMG_0386

IMG_0384

Code Running on Arduino UNO

/*
   CHRISTMAS TREE API

  * Using Arduino Uno, Arduino Ethernet Shield, Maplin Relay Shield
  * Maplin codes: NO2DH, N33KU, N30KU
  
  * Optional: USB B cable for programming, stacking headers, free standing PSU box (enclosure), adapters

  * Notes: Christmas tree lights circuit attached to relay sheild pin 4

  created 18 Dec 2014
  by Nick Kewney

  */

#include <SPI.h>
#include <Ethernet.h>

IPAddress ip(10, 100, 1, 177); // give the shield an IP

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // give the shield a MAC 

unsigned int relayPin = 4;

EthernetServer server(80); // init EthernetServer on port 80

String queryString; // for reading target state

void setup() {
   Serial.begin(9600);
   while (!Serial) { // wait!
     ;
   }
   
   // start the connection and web server:
   Ethernet.begin(mac, ip);
   server.begin();
   Serial.print("server is at ");
   Serial.println(Ethernet.localIP());
   
   pinMode(relayPin,OUTPUT); // set up the code to send relay shield
}

void loop() {
   // listen for requests
   EthernetClient client = server.available();
   if (client) {
     Serial.println("new switcher just connected");
     // an http request ends with a blank line
     boolean isBlankLine = true;
     while (client.connected()) {
       if (client.available()) {
         char c = client.read();
         
         // get the light/dark querystring parameters from the HTTP header
        if (queryString.length() < 100) {
          queryString += c; 
        } 
        
         Serial.write(c);
         
         if (c == 'n' && isBlankLine) {
           // send a standard http response header as JSON for our consuming service (treeapi.thelayer.com)
           client.println("HTTP/1.1 200 OK");
           client.println("Content-Type: application/json");
           client.println("Access-Control-Allow-Origin: *"); // needed even for subdomains
           client.println("Connection: close");  // the connection will be closed after completion of the response
           client.println();
           
          if(queryString.indexOf("light") >0)//checks for light on QS
          {
            digitalWrite(relayPin,HIGH);    // set light pin to HIGH
            client.println("{ "State": "Light" }");
          }
          if(queryString.indexOf("dark") >0)//checks for dark on QS
          {
            digitalWrite(relayPin,LOW);    // set light pin to LOW
            client.println("{ "State": "Dark" }");
          }

          queryString=""; // clear this for next request
        
          break;
         }
         if (c == 'n') {
           isBlankLine = true;
         }
         else if (c != 'r') {
           isBlankLine = false;
         }
       }
     }
     delay(1);
     client.stop();  // close the connection:
     Serial.println("client disconnected");
   }
}

 

The number of records in the table exceeds the maximum number of 5000 – Dynamics

When attempting to export records via Microsoft Dynamics and the number of records is greater than 5,000, you may receive this error.

The number of records in the table exceeds the maximum number of 5000. Set a filter to decrease the number of records in the table. Exporting too many records at once can affect system performance.

Dynamics CRM Online

Follow this guide.

Dynamics NAV

Open using your preferred ClientUserSettings.config

NAV 2013 R2
Default location is

C:Users<username>AppDataRoamingMicrosoftMicrosoft Dynamics NAV71

NAV 2013
Default location is

C:Users<username>AppDataRoamingMicrosoftMicrosoft Dynamics NAV70

NAV 2009
On Windows 7, Windows Vista, or Windows Server 2008, the default location is

C:Users<username>AppDataLocalMicrosoftMicrosoft Dynamics NAV

On Windows Server 2003 or Windows XP, the default location of this file is

C:Documents and Settings<username>Local SettingsApplication DataMicrosoftMicrosoft Dynamics NAV

Where

<username>

is the name of the user.

Change MaxNoOfXMLRecordsToSend property value from 5000 to, for example, the maximum integer value of 2147483647

<add key="MaxNoOfXMLRecordsToSend" value="2147483647" />

If you’ll insert a number bigger that 2147483647 you’ll receive the following error message:

The MaxNoOfXMLRecordsToSend config

<add key="MaxNoOfXMLRecordsToSend" value="2147483647" />

Duration setting must have a value between -2,147,483,648 and 2,147,483,647.

Self-Executing Functions in JavaScript

I’ve been steadily migrating my JavaScript assets to use self executing functions (and more recently literals) as they are a good way to enforce scope on variables and make your JavaScript more readable.

The examples below show the difference between implementing a self-executing function and using literals.

I have found that on most browsers (except Safari), there is a considerable performance win when using literals.

Creating a module via a self-executing function

obj = (function () {

  var _privateVar;
  var publicVar;

  function setPrivateVar(value) {
     _privateVar = value;
  }

  function getPrivateVar(value) {
    return _privateVar;
  }
  
  // api
  return {
    publicVar: publicVar,
    setPrivateVar: setPrivateVar,
    getPrivateVar: getPrivateVar
  }
}());

 Creating a module via object literals

obj = {
  _privateVar: undefined,
  publicVar: undefined,

  setPrivateVar: function setPrivateVar(value) {
    obj._privateVar = value;
  },

  getPrivateVar: function getPrivateVar(value) {
    return obj._privateVar;
  }
};