Skip to content

Instantly share code, notes, and snippets.

View steinbring's full-sized avatar

Joe Steinbring steinbring

View GitHub Profile
@steinbring
steinbring / index.html
Created May 30, 2018 21:04
Want to do "autocomplete" for states in a webform? Using the <datalist> tag, you can use this ...
<input list="states" name="state" size="25" placeholder="state">
<datalist id="states">
<option value="Alabama">
<option value="Alaska">
<option value="Arizona">
<option value="Arkansas">
<option value="California">
<option value="Colorado">
<option value="Connecticut">
@steinbring
steinbring / index.html
Created May 30, 2018 21:03
Want to do "autocomplete" for cities in a webform? Using the <datalist> tag, you can use this ...
<input list="cities" name="city" size="25" placeholder="city">
<datalist id="cities">
<option value="Aberdeen">
<option value="Abilene">
<option value="Aguada">
<option value="Aguas">
<option value="Aibonito">
<option value="Akron">
<option value="Albany">
@steinbring
steinbring / index.cfm
Created November 19, 2015 02:45
I stumbled across this the other day. Want to remove null items from a list? Convert it to an array and back again.
<cfscript>
//A list that includes null items
list = 'Joe,Lisa,,,Beth,John,,,Tom,Liz,Tina,,,,,,,,Omar';
writedump(list);
//Clear out the null items
list = ArrayToList(ListToArray(list));
writedump(list);
</cfscript>
@steinbring
steinbring / index.html
Last active August 29, 2015 14:27
This shows you how to take the contents of a selected image file and display it on change within the page.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<!-- We are going to display it in an <img> tag, so we will only accept image files -->
<input type='file' accept='images/*' onchange='openFile(event);'>
<div id="TheImageContents">
@steinbring
steinbring / TestCreditCard.php
Last active August 29, 2015 14:06
This code uses the Luhn formula to validate your credit card number. This acts as error detection, basicly. It could still be a fake number. I wrote this in PHP because the company is doing more PHP and I figure that I could use the practice. :)
<?
// What credit card number are we validating?
$CreditCardNumber = '5554172297437101';
// Output the subject
echo $CreditCardNumber;
// Save the credit card number for later
$LastDigit = substr($CreditCardNumber, strlen($CreditCardNumber) - 1);
// Drop the last digit
$CreditCardNumber = substr_replace($CreditCardNumber ,"",-1);
// Reverse the string
@steinbring
steinbring / ResizeImage.php
Last active August 29, 2015 14:06
No matter what the original width and height is of the source image, this function will resize your source file to a particular width and height of your choosing. The function preserves the original aspect ratio and then just adds solid bars on the top or bottom, if needed.
<!--
Description: No matter what the original width and height is of the source image, this function will resize your source file to a particular width and height of your choosing. The function preserves the original aspect ratio and then just adds solid bars on the top or bottom, if needed.
Author: Joe Steinbring (http://steinbring.net)
Date: 09/12/2014
-->
<?php
function imageResize($NewWidth, $NewHeight, $NewFilename, $OldFilename) {
// Get the details on the target $OldFilename
@steinbring
steinbring / GeoLocate.php
Last active August 29, 2015 14:06
This gets the user's location, via their IP address. If the user's IP address is reported as being in an internal range, it does an additional query for their public IP (This is mainly just useful in a development scenario).
<?php
function get_public_ip_address()
{
// SOURCE: https://github.com/dotancohen/utility-functions/blob/master/ip-addresses.php
$url="simplesniff.com/ip";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
@steinbring
steinbring / gist:3365a5e4d48d90bef071
Last active August 29, 2015 14:05
How I implimented Add, Delete, and Clone for 'Notes Vault'
$scope.removeItem = function() {
$scope.$storage.notes.splice(document.getElementById('selectedNote').value, 1);
document.getElementById('title').value = '';
document.getElementById('content').value = '';
}
$scope.addItem = function() {
$scope.$storage.notes.push({
"title": "",
"content": ""
});
@steinbring
steinbring / gist:121f10acb4eb8a6ca30f
Created August 18, 2014 21:15
How to populate a select box with the contents of the array $storage.notes. You can reference it in other form elements as {{savedNote}}.
<select ng-model="savedNote" ng-options="n.title for n in $storage.notes" id="selectedNote">
<option value="">-- Saved Notes --</option>
</select>
@steinbring
steinbring / gist:eb3db85786e024224101
Created August 18, 2014 20:25
How to instantiate the ngStorage module with defaults
// The module
var NotesApp = angular.module('NotesApp', ['ngStorage']);
// The controller
NotesApp.controller('NotesCtrl', function($scope, $localStorage) {
// Set a default
$scope.$storage = $localStorage.$default({
"notes": [{
"title": "What is the notes vault?",
"content": "It is an AngularJS experiment, done by Joe Steinbring. I think it is fairly cool."