Skip to content

Instantly share code, notes, and snippets.

@wizard04wsu
wizard04wsu / phoneNumbers.js
Created May 1, 2014 18:37
Regular Expressions for U.S. Phone Numbers
//Regular Expressions for U.S. Phone Numbers
//
//See http://en.wikipedia.org/wiki/North_American_Numbering_Plan
//
//Spaces, dashes, or periods are allowed as separators.
//Extensions can be recognized by several strings: #, x, x., ext, ext., extension
//
//Area code: $1$2
//Exchange code: $3
//Station code: $4
@wizard04wsu
wizard04wsu / autonumber.vbs
Created May 1, 2014 18:45
Get ID of last inserted record in Access
'Get the value of the autonumber field for the last record inserted into an Access database via the current connection.
set rst = objConn.Execute("SELECT @@IDENTITY")
id = rst(0)
@wizard04wsu
wizard04wsu / VBA_MaxMin.vbs
Last active March 22, 2017 16:39
VBA Max and Min functions
Function max(ParamArray ListItems() As Variant)
Dim i As Integer
If UBound(ListItems) >= 0 Then
max = ListItems(0)
For i = 1 To UBound(ListItems)
If ListItems(i) > max Then max = ListItems(i)
Next i
End If
@wizard04wsu
wizard04wsu / CDecForQuery.vbs
Created December 10, 2014 21:13
MS Access VBA query function to apply CDec() to a number field (helps avoid rounding errors)
Function CDecForQuery(val)
CDecForQuery = CDec(val)
End Function
@wizard04wsu
wizard04wsu / TradRound.vbs
Last active March 22, 2017 16:37
VBA function to round a number ending in 5 the traditional way, instead of the "round to even" logic. Unfortunately, this is significantly slower.
Function TradRound(val As Double, Optional places As Integer) As Double
Dim divisor As Double
Dim val2 As Double
If IsMissing(places) Then places = 0
divisor = 10 ^ places
val2 = val * divisor - Int(val * divisor)
@wizard04wsu
wizard04wsu / HTMLescaper.htm
Created March 25, 2015 13:07
Form to escape/unescape HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Encoder</title>
<script type="text/javascript" src="encoder.js"></script>
@wizard04wsu
wizard04wsu / multiColumnSelect.css
Last active October 30, 2015 13:58
Format a select box with classname "multiColumnSelect" to emulate columns. The first <optgroup> (which must be empty for the CSS to work correctly) acts as the headings.
select.multiColumnSelect optgroup, select.multiColumnSelect option {
font-family:"Courier New", Courier, monospace;
font-style:normal;
padding-left:3px;
}
select.multiColumnSelect optgroup {
font-weight:bold;
text-decoration:underline;
}
@wizard04wsu
wizard04wsu / encodeHTML5.js
Last active September 10, 2017 18:39
JavaScript functions to encode HTML5 markup-significant characters and to decode HTML5 character references
//encode HTML markup-significant characters
// keepCharacterReferences: if true, the ampersands of HTML5 character references will not be encoded
function encodeHTML(str, keepCharacterReferences){
"use strict";
var namedChars, rxp;
if(keepCharacterReferences){
//see http://www.w3.org/TR/html5/syntax.html#named-character-references
//this list excludes: AMP amp LT lt GT gt QUOT quot apos
namedChars = "Aacute|aacute|Abreve|abreve|ac|acd|acE|Acirc|acirc|acute|Acy|acy|AElig|aelig|af|Afr|afr|Agrave|agrave|alefsym|aleph|Alpha|alpha|Amacr|amacr|amalg|And|and|andand|andd|andslope|andv|ang|ange|angle|angmsd|angmsdaa|angmsdab|angmsdac|angmsdad|angmsdae|angmsdaf|angmsdag|angmsdah|angrt|angrtvb|angrtvbd|angsph|angst|angzarr|Aogon|aogon|Aopf|aopf|ap|apacir|apE|ape|apid|ApplyFunction|approx|approxeq|Aring|aring|Ascr|ascr|Assign|ast|asymp|asympeq|Atilde|atilde|Auml|auml|awconint|awint|backcong|backepsilon|backprime|backsim|backsimeq|Backslash|Barv|barvee|Barwed|barwed|barwedge|bbrk|bbrktbrk|bcong|Bcy|bcy|bdquo|beca
@wizard04wsu
wizard04wsu / keyboard.html
Last active September 30, 2015 14:50
Display values given for keyboard events.
<!DOCTYPE html>
<html lang="en">
<head>
<!-- to prevent IE from using compatibility mode -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="UTF-8">
@wizard04wsu
wizard04wsu / classnames.js
Last active November 17, 2015 18:40
Class name functions
function removeClass(elem){
var classes, rxp;
if(!elem){
throw new Error("Missing parameter: elem");
}
classes = Array.prototype.slice.call(arguments, 1).join(" ").trim();