Skip to content

Instantly share code, notes, and snippets.

View ericjames's full-sized avatar

Eric James ericjames

View GitHub Profile
@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 / 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 / wordpressListChildPages.html
Created July 1, 2017 21:09
Wordpress List Child Pages with Thumbnails
<?php if (is_page('web-design')) : ?>
<?php $i = 0; ?>
<div>
<ul>
<?php
$args = array(
'post_parent' => $post->ID,
'post_type' => 'page',
'post_status' => 'publish',
'orderby' => 'menu_order',
@ericjames
ericjames / wordpressTableOfContents.html
Created July 1, 2017 21:08
Wordpress Table of Contents
<ul>
<?php global $query_string;
query_posts ( $query_string . '&posts_per_page=5&offset=0'); ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="#post-<?php the_ID(); ?>" title="Read <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br />
<span><?php the_time('n/j/y')?></span> - <span><?php the_author() ?></span> - <?php the_tags( '<span>', ', ', '</span>'); ?>
</li>
<?php endwhile; ?>
</ul>
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(applicationDidEnterBackground),
name: NSNotification.Name.UIApplicationDidEnterBackground,
object: nil)
NotificationCenter.default.addObserver(self,
@IBOutlet weak var myTextField: UITextField!
// Dismisses keyboard by touching outside of keyboard
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
// Dismiss keyboard
self.view.endEditing(true)
}
@ericjames
ericjames / cookies.swift
Last active August 30, 2021 16:51
Swift 4 Get Cookie
func readCookie() {
let sharedCookieStorage = HTTPCookieStorage.shared
for cookie in sharedCookieStorage.cookies as [HTTPCookie]! {
print(cookie)
}
@ericjames
ericjames / php-css-js-concat-minify.php
Created May 27, 2017 06:08
Concatenate or minify CSS and JS using php
<?php
/**
* @return none
*/
function prepareView()
{
compressFiles([
'css/src/normalize.css',
'css/src/styles.css',
@ericjames
ericjames / quickPageLoadCounter
Created December 20, 2016 20:16
Count number of milliseconds to reach desired "page complete" condition
var counter = setInterval(timer, 1);
var count = 0;
function timer() {
count++;
var ele = document.getElementById("thisdiv");
if (ele.className.indexOf('ng-hide') !== -1) {
clearInterval(counter);
console.log(count, count / 1000);
setTimeout(function() {
@ericjames
ericjames / convertKMLtoGoogleMapsPolyLine.js
Last active December 19, 2016 16:03
Converts KML shapefile syntax into a Google Maps Polyline. It is rather ironic this is not built into Gmaps since it is Google's spec.
function getPolylines(geometry, style) {
// Parse Geometry
var kmlstring = geometry.toString();
kmlstring = kmlstring.substr(40);
kmlstring = kmlstring.substr(0, kmlstring.length - 43);
var linestrings = kmlstring.split("</coordinates></LineString><LineString><coordinates>");