Skip to content

Instantly share code, notes, and snippets.

View ericjames's full-sized avatar

Eric James ericjames

View GitHub Profile
@ericjames
ericjames / wordpressChildPageMenu
Created July 1, 2017 21:25
Wordpress Child Page Menu
<?php
if (is_page()) {
$this_page = $post->ID;
if ($post->post_parent) $this_page= $post->post_parent;
$children = get_page_children($this_page, get_pages());
if($children) {
$my_pages .= '<ul>';
$my_pages .= wp_list_pages('title_li=&depth=1&child_of='.$post->ID.'&echo=0');
$my_pages .= '</ul>';
}
@ericjames
ericjames / coordinate-distance.php
Last active April 30, 2018 15:36
PHP - Distance Between Two Coordinate Sets (Triangle Distance and Earth Distance)
<?php
echo triangleDistance(44.977840, -93.258358, 44.973551, -93.265175);
echo "<br />";
echo "<br />";
echo earthDistance(44.977840, -93.258358, 44.973551, -93.265175);
function triangleDistance($startLatitude, $startLongitude, $endLatitude, $endLongitude)
{
$kmPerLat = 111.000;
@ericjames
ericjames / swift3-deserialize-cookie
Last active August 16, 2017 16:34
Swift 3: Deserialize cookie values obtained from WebView
@ericjames
ericjames / swift3-gesture-recognizer-uiwebview.swift
Last active August 22, 2017 20:12
Swift 3 - Listen in on UIGestureRecognizer INSIDE of a UIWebView
class WebViewController: UIViewController, UIGestureRecognizerDelegate {
@IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// WebView: Register tap
let panGesture = UITapGestureRecognizer(target: self, action: #selector(doneDragging(_:)))
panGesture.delegate = self
webView.addGestureRecognizer(panGesture)
@ericjames
ericjames / swift3-insertbetween
Created August 29, 2017 18:35
Swift 3 - Insert a string inside of a string at a random location
var str = "123456789abcdefgh"
let keyIndex = Int(arc4random_uniform(50))
let newIndex = str.index(str.startIndex, offsetBy: keyIndex)
let keyTwo = str.substring(to: newIndex)
let keyOne = str.substring(from: newIndex)
str = keyTwo + "0000000" + keyOne
@ericjames
ericjames / sassMixinColorBackground.scss
Created October 9, 2017 19:39
SASS Mixin for Color and Background
@mixin setColor($property, $varName, $color) {
@if $property == 'text' {
color: $color;
color: var($varName, $color);
}
@if $property == 'background' {
background: $color;
background: var($varName, $color);
}
}
@ericjames
ericjames / getAllStylesheetRules.js
Created October 9, 2017 20:06
JavaScript: Get all stylesheet rules
function getAllColors() {
for (var s in document.styleSheets) {
var stylesheet = document.styleSheets[s];
if (stylesheet.title == 'themecolors') {
var rule = stylesheet.cssRules[0] || stylesheet.rules[0];
// if (rule.style.color) {
// rule.style.color = "red"
@ericjames
ericjames / php-kml-generator.php
Created October 23, 2017 02:07
PHP KML Generator - Generates a KML file from database stored KML geometry
<?php
$routenum = $_REQUEST['routenum'];
$style = $_REQUEST['style'];
$tableRoutes = "";
$key = "&key=";
$callback = "&callback=jsonp";
$select = "geometry";
$query = "http://www.google.com/fusiontables/api/query?sql=SELECT+{$select}+FROM+{$tableRoutes}+WHERE+route='{$routenum}'{$key}{$callback}";
$getfile = file_get_contents($query);
$geometry = substr($getfile, 10, -2);
@ericjames
ericjames / php-save-feedback.php
Last active October 23, 2017 02:09
PHP Save Feedback - A simple script to store some input field data into a local text file
<?php
$date = date ("l, F jS, Y");
$time = date ("h:i A");
$msg = "";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
}
@ericjames
ericjames / google-maps-create-polyline-from-coordinates
Created October 23, 2017 14:51
Google Maps Create Polyline from Coordinates - Given a set of coordinates, this function will generate a polyline object
function createLine(linepoints, style, stroke, opacity, zIndex) {
var coordArray = [];
for (var i in linepoints) {
var coord = linepoints[i].split(",");
var lat = coord[1];
var lng = coord[0];
var lineCoord = new google.maps.LatLng(lat, lng);
coordArray.push(lineCoord);
}