Skip to content

Instantly share code, notes, and snippets.

View mycarrysun's full-sized avatar
🖱️
Mousin around

Mike Harrison mycarrysun

🖱️
Mousin around
View GitHub Profile
@mycarrysun
mycarrysun / InitsWithProps.ts
Created December 9, 2019 21:36
Typescript Decorator function to populate the class properties with the first argument as an object
export function InitsWithProps<T extends {new(...args: any[]): {}}>(constructor: T) {
return class extends constructor {
constructor(...args: any[]) {
super(...args);
if (args && args.length) {
Object.assign(this, args[0]); //args[0] must be an object
}
}
};
@mycarrysun
mycarrysun / getRouteStates.js
Created September 18, 2019 18:00
Get all states in a Google Maps Directions Result
// route is a DirectionsRoute interface
// see: https://developers.google.com/maps/documentation/javascript/reference/directions#DirectionsRoute
function getRouteStates(route) {
let states = [],
routeLeg = route.legs[0] // first leg of the route is the starting point
states.push(
routeLeg.start_address
.split(',') // split on commas
@mycarrysun
mycarrysun / npm_set_script_shell_bash
Created June 16, 2018 17:26
NPM set script shell to bash for WIndows scripts to run properly
npm config set script-shell "C:\\Program Files\\Git\\bin\\bash.exe"
//or
npm config set script-shell "C:\\Program Files (x86)\\git\\bin\\bash.exe"
@mycarrysun
mycarrysun / PHP-get-timezone-from-address.php
Created December 27, 2017 20:11
Gets the Timezone from an Address based on the current time
<?php
$addr = 'Columbus,OH,43235';
$maps_api_key = 'insert key here';
/**
* Gets the timezone id (eg. America/New_York, America/Detroit)
* @param string $address
* @return string|bool
*/
function get_timezone_from_address($address){
@mycarrysun
mycarrysun / PHP-Get-Geocode-from-Address
Created December 27, 2017 19:59 — forked from madeinnordeste/PHP-Get-Geocode-from-Address
PHP - Get Geocode (lat, long) from Address
<?php
$address = 'avenida+gustavo+paiva,maceio,alagoas,brasil';
$geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$address.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$long = $output->results[0]->geometry->location->lng;
@mycarrysun
mycarrysun / nf_grecaptcha_explicit_render.js
Last active November 8, 2016 20:26
Modifications to ninja forms version 2.9.x recaptcha field so multiple recaptchas will work on a single page
function nf_grecaptcha_explicit_render(){
jQuery('.g-recaptcha').each(function(){
var sitekey = jQuery(this).data('sitekey');
grecaptcha.render(this, {
'sitekey':sitekey
})
});
}