Skip to content

Instantly share code, notes, and snippets.

@jsven69gist
jsven69gist / gist:8949805
Created February 12, 2014 03:52
JavaScript: Simple HTML doc with JS assert() test suite
<html>
<head>
<title>Test Suite</title>
<meta charset="utf-8" />
<script>
function assert(value, desc) {
var li = document.createElement('li');
li.className = value ? 'pass' : 'fail';
li.appendChild(document.createTextNode(desc));
@jsven69gist
jsven69gist / gist:8949732
Created February 12, 2014 03:44
JavaScript: assert()
// Asserts expression
function assert(value, desc) {
var li = document.createElement('li');
li.className = value ? 'pass' : 'fail'; // li css class must be created
li.appendChild(document.createTextNode(desc));
document.getElementById('results').appendChild(li); // Assumes ul id is 'results'
}
@jsven69gist
jsven69gist / gist:8687484
Created January 29, 2014 13:04
Apache: SSL (https) configuration/setup on Ubuntu
SSL on Ubuntu
Install ss-cert package:
apt-get install ssl-cert
Activate ssl module on Apache2:
a2enmod ssl
Configure Apache2 for https:
a2ensite default-ssl
@jsven69gist
jsven69gist / gist:8616727
Created January 25, 2014 13:55
jQuery: Disable <enter> in input elements within "#Form" with optional focusshift to next input element
// Disables enter key on all input fields on #Form. Can also shift focus to next input field
$('#Form').on('keypress', 'input', function(event) {
if (event.keyCode == 13) {
event.preventDefault();
if ('You want enter2tab') {
$(this).next('input').focus();
} else { // Just disable enter key
return false;
}
@jsven69gist
jsven69gist / gist:8614824
Created January 25, 2014 11:05
jQuery: Set background-color on focus with addClass
// Add colorclass 'yellow' (background-color: #FFFF66) on focus to elements with class 'text'
$('.text').on('focus', function(event) {
$(this).addClass('yellow');
});
// Remove added colorclass 'yellow' on blur from elements with class 'text'
$('.text').on('blur', function(event) {
$(this).removeClass('yellow');
});
@jsven69gist
jsven69gist / gist:8554881
Created January 22, 2014 07:40
jQuery: Select with add to table with "self-delete" button in table row
function delpart(id) {
$(id).closest('tr').remove();
}
$("#AddPart").click(function() {
'use strict';
var userID = $('#sel_Participants').val(); // Get value from select
var userName = $('#sel_Participants option:selected').text(); // Get text from select
@jsven69gist
jsven69gist / gist:8519405
Created January 20, 2014 12:53
jQuery: Select w/child populated with Ajax request
$('#ParentID').change(function() { // Populate selectbox #ChildID based on selected option in #ParentID
// alert( "Handler for .change() called." );
// Ajax data
var data = new Object();
data.parentID = $('#ParentID').val(); // Get value from select
// Ajax options
var options = new Object();
options.data = data;
@jsven69gist
jsven69gist / gist:8370166
Created January 11, 2014 12:07
jQuery: Ajax request
// Ajax data
var data = new Object();
data.property1 = 'Prop1';
data.property2 = 'Prop2';
// Ajax options
var options = new Object();
options.data = data;
options.dataType = 'text';
options.type = 'post';
@jsven69gist
jsven69gist / gist:8369902
Created January 11, 2014 11:37
jQuery: document.ready()
$(document).ready(function() {
});
@jsven69gist
jsven69gist / gist:7846680
Created December 7, 2013 18:31
MySQL Cheat Sheet
MySQL Cheat Sheet
Indexes:
- UNIQUE
- INDEX
- PRIMARY KEY
- FULLTEXT (MyISAM engine only)
SHOW ENGINES -> shows available storage engines and default storage engine