Skip to content

Instantly share code, notes, and snippets.

View ericjames's full-sized avatar

Eric James ericjames

View GitHub Profile
@ericjames
ericjames / google-maps-fusion-tables.js
Created November 12, 2017 18:09
Fusion Tables set new layer and set styles
// Will grab a fusion table layer for each
function getFusionTableLayer(mapLayer, fusiontableID) {
var fusionLayer = new google.maps.FusionTablesLayer({
query: {
select: '*',
from: fusiontableID
}
});
@ericjames
ericjames / writing-file-via-query.php
Created November 1, 2017 17:05
Writing a file on a server via URL POST
<?php
error_reporting(-1);
header('Access-Control-Allow-Origin: *');
$store = isset($_POST['store']) ? substr($_POST['store'],0,10) : false;
$fp = fopen('test.txt', 'r+');
if ($store) {
@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);
}
@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 / 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 / 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 / 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 / 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 / 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-deserialize-cookie
Last active August 16, 2017 16:34
Swift 3: Deserialize cookie values obtained from WebView