Skip to content

Instantly share code, notes, and snippets.

View steinbring's full-sized avatar

Joe Steinbring steinbring

View GitHub Profile
@steinbring
steinbring / Geolocation.html
Created April 30, 2014 03:34
How to use navigator.geolocation.getCurrentPosition() and the Google Reverse Geocoding API to prepopulate an address form
<!DOCTYPE html>
<html>
<head>
<title>Find Me!</title>
</head>
<body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
@steinbring
steinbring / gist:d5ce33ad41691a762966
Created May 3, 2014 17:32
How to use navigator.geolocation.getCurrentPosition(), Google Reverse Geocoding API, the Google Static Maps API, and the Google Street View API to find yourself
<!--
Joe Steinbring
http://steinbring.net
///////////////////////
This is part 2. To see the original version, check out https://gist.github.com/steinbring/368a9e693c8c765125df.
-->
<!DOCTYPE html>
<html>
<head>
<title>Find Me!</title>
@steinbring
steinbring / geolocate.html
Created May 11, 2014 21:03
How to use JavaScript to sort a list of locations by how far they are from your current location
<!--
Joe Steinbring
http://steinbring.net
-->
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
@steinbring
steinbring / SortStations.js
Created August 10, 2014 16:27
Take an array of stations (with marketCity as an attribute) and create an array of marketCities (with stations as an attribute)
// Define the unique market cities
$scope.marketCities = [];
for (var i = 0; i < data.query.results.station.length; i++){
// if it isn't already there, add it
if(i !== 0 && data.query.results.station[i].marketCity !== data.query.results.station[i-1].marketCity){
$scope.marketCities.push({ label: data.query.results.station[i].marketCity, stations: [data.query.results.station[i]]});
}else if(i == 0){
$scope.marketCities.push({ label: data.query.results.station[i].marketCity, stations: [data.query.results.station[i]]});
}else if(data.query.results.station[i].id !== data.query.results.station[i-1].id){
// is the market already there? well, just add the station then.
@steinbring
steinbring / index
Created August 10, 2014 16:42
Loop over an array, inside of another array using ng-repeat; limit output using ng-show
<ul>
<li ng-repeat="marketCity in marketCities">
<h2>{{marketCity.label}}</h2>
<ul>
<li ng-repeat="station in marketCity.stations">
<div class="StationInfo">
<div class="label">
{{station.orgDisplayName}}
</div>
@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."
@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: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 / 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 / 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