Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / modalDialog.css
Last active November 13, 2024 19:02
This script (and CSS stylesheet) allows you to create a custom modal dialog box that will not allow the user to interact with the rest of the page.
.modalMask {
display:none;
}
.modalMask.active {
display:block;
position:fixed;
top:0;
left:0;
bottom:0;
right:0;
@wizard04wsu
wizard04wsu / bookmarklet.css
Last active July 1, 2020 17:53
CSS styling for bookmarklet links ( Updated version here: https://gist.github.com/wizard04wsu/a22bb88dcafb5229320e0e02ba08ef73 )
/* just add either class .peel-br or .peel-tr to your bookmarklet link */
a.peel-br, a.peel-tr {
display:inline-block;
position:relative;
padding:0.4em 0.6em;
border:1px solid #B4B4B4;
border-radius:5px;
background-color:#E6E6E6;
color:#333;