Skip to content

Instantly share code, notes, and snippets.

View ericjames's full-sized avatar

Eric James ericjames

View GitHub Profile
var polys = document.querySelectorAll('polygon,polyline');
[].forEach.call(polys,convertPolyToPath);
function convertPolyToPath(poly){
var svgNS = poly.ownerSVGElement.namespaceURI;
var path = document.createElementNS(svgNS,'path');
var points = poly.getAttribute('points').split(/\s+|,/);
var x0=points.shift(), y0=points.shift();
var pathdata = 'M'+x0+','+y0+'L'+points.join(' ');
if (poly.tagName=='polygon') pathdata+='z';
@ericjames
ericjames / scrolltoarticle.js
Created November 6, 2016 19:06
jQuery scrollto article on page
$.fn.scrollTo = function(ele) {
$(this).animate({
scrollTop: $(ele).position().top
}, 1000);
};
$('.scrollto').click(function(e) {
e.preventDefault();
var target = $(this).attr('href');
var scrollpx = $(target).offset().top;
@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>");
@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 / 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 / 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)
}
@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)
}
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self,
selector: #selector(applicationDidEnterBackground),
name: NSNotification.Name.UIApplicationDidEnterBackground,
object: nil)
NotificationCenter.default.addObserver(self,
@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>
@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',