Skip to content

Instantly share code, notes, and snippets.

@ConnerAiken
ConnerAiken / clean.php
Created July 22, 2017 18:26
Clean email form input in PHP
function cleanInput($input) {
// Pass the $_GET, $_POST or $_REQUEST array
$output = array();
foreach ($input as $key=>$value) {
$o = $value;
// Make sure it's within the max length
$o = substr($o,0,256);
@ConnerAiken
ConnerAiken / ex.js
Created July 7, 2017 19:49
Disable right-click in webpages
document.addEventListener('contextmenu', event => event.preventDefault());
// This will annoy users and some browsers prevent this behavior so test accordingly.
@ConnerAiken
ConnerAiken / index.html
Last active June 29, 2017 19:12
ES6: Promise Chain and Fetch API
<!DOCTYPE html>
<html lang="en">
<head>
<title>ES6: Promises and Fetch API Example</title>
<meta charset="utf-8">
<meta author="Conner Aiken">
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
@ConnerAiken
ConnerAiken / ajax-hook.js
Last active June 27, 2017 22:17
Hook into all AJAX calls
/* =================== jQuery ===================== */
$(document).ajaxSend(function() {
alert("Triggered ajaxSend hook.");
});
$('#clickBtn').click(function() {
$.getJSON("https://crossorigin.me/https://api.darksky.net/forecast/037352c0951701a563b624359ea6111f/42.3601,-71.0589", function(json) {
console.log("JSON Data:", json);
});
@ConnerAiken
ConnerAiken / example.sh
Created June 17, 2017 22:39
Resent bash command line history - linux security
history -cw
// or
reset
@ConnerAiken
ConnerAiken / generateTestFile.bat
Created June 8, 2017 15:20
Generate test text files of all sizes
REM generateTestFile.bat testFileName.txt 900000
fsutil file createnew %1 %2
@ConnerAiken
ConnerAiken / Tree.js
Last active June 8, 2017 00:41
Binary search tree example in javascript
'use strict';
/*
* Binary search tree with in-order iteration.
* http://greim.github.io/gen/dist/00-intro.html
*/
class Tree {
add(value) {
if (this.root) this.root.add(value);
@ConnerAiken
ConnerAiken / dangerous-extensions.json
Last active June 7, 2017 21:04
A collection of dangerous extensions to filter out of file uploads.
[
{
"ext":"adp",
"description":"Access Project (Microsoft)"
},
{
"ext":"app",
"description":"Executable Application"
},
{
@ConnerAiken
ConnerAiken / js-class-examples.js
Last active June 7, 2017 19:06
Examples of ES5 vs ES6 Classes
/* ==============================================================
==== ES5 Classes
================================================================*/
'use strict';
function Shape(id, x, y) {
this.id = id;
this.setLocation(x, y);
}
@ConnerAiken
ConnerAiken / index.html
Created May 31, 2017 15:30
Very basic hamburger menu example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>