Skip to content

Instantly share code, notes, and snippets.

@pospi
pospi / parse-latlng.js
Last active August 29, 2015 14:11
Parse common lat/lng formats
var parseLatLng = (function()
{
var matchLocDecimal = /^\s*(-?\d+)(\.\d+)?\s*°?\s*(N|S)?(,|\s)+(-?\d+)(\.\d+)?\s*°?\s*(E|W)?\s*$/;
var matchLocDegrees = /^\s*(-?\d+)°?\s*((\d+)(\.\d+)?'?)?\s*(N|S)?(,|\s)+(-?\d+)°?\s*((\d+)(\.\d+)?'?)?\s*(E|W)?\s*$/;
var matchLocCompass = /^\s*(-?\d+)°?\s*((\d+)('|\s)+)?\s*((\d+)(\.\d+)?(''|")?)?\s*(N|S)?(,|\s)+(-?\d+)°?\s*((\d+)('|\s)+)?\s*((\d+)(\.\d+)?(''|")?)?\s*(E|W)?\s*$/;
return function(val)
{
var matches,
lat, lng,
@pospi
pospi / check-for-popup-blocking.js
Created August 28, 2014 23:47
Detect blocked popup windows in all browsers
window.isPopupBlocked = function(popup_window, cb)
{
var CHROME_CHECK_TIME = 2000; // the only way to detect this in Chrome is to wait a bit and see if the window is present
function _is_popup_blocked(popup)
{
return !popup.innerHeight;
}
if (popup_window) {
@pospi
pospi / ie-compatible-rotation.less
Created August 18, 2014 07:01
IE6+ compatible rotation mixin using matrices
.rotate-ie(@degrees) {
-webkit-transform: rotate(@degrees);
-o-transform: rotate(@degrees);
transform: rotate(@degrees);
@cos: cos(@degrees);
@sin: sin(@degrees);
@nl: `"\n"`; // Newline
@pospi
pospi / leaflet-multi-geojson-layers.js
Last active September 23, 2016 16:13
Handle multiple geoJSON layers in a Leaflet.js angular directive
/**
* Service to manage geoJSON layering with Leaflet.js' angular directive, which only allows 1 set of geoJSON data.
*
* Assuming you have a leaflet directive with its 'geojson' attribute set to `geojson`, usage is as follows:
* var layers = new GeoJSONLayers();
*
* layers.addLayer('myLayer', geoJSON, function(feature) { return { fillColor: '#00F' }; });
* $scope.geojson = layers.get();
*
* layers.removeLayer('myLayer');
@pospi
pospi / git-post-receive-deployment.sh
Last active August 29, 2015 13:55
A generic git post-receive hook for auto-deploying applications when pushed to.
#!/bin/bash
#------------------------------------------------------------------------------#
# CONFIGURATION
# You will need the following variables set in the git repository to deploy from:
# git config --bool receive.denyCurrentBranch false
# git config --bool core.bare false
# git config --path core.worktree [DEPLOYMENT_DIR]
@pospi
pospi / wordpress-hostchange.sql
Created January 30, 2014 23:04
Some SQL for quickly moving WordPress sites between servers.
SET @FROMDOMAIN = 'myolddomain.com';
SET @TODOMAIN = 'mynewdomain.com';
SET @FROMSCHEME = 'http';
SET @TOSCHEME = 'http';
#-------------- STANDARD TABLES -------------#
UPDATE wp_options
@pospi
pospi / em-font-size.less
Last active January 4, 2016 04:49
Calculate sizes in EMs easily by converting from other units
@BASE_FONT_SIZE : 16px;
// translate units by parent element ratio
.emsize(@property, @desired, @base : @BASE_FONT_SIZE) {
@{property}: 1em * (unit(@desired) / unit(@base));
}
// a wrapper for setting font size
.emfz(@desired, @base : @BASE_FONT_SIZE) {
.emsize(font-size, @desired, @base);
@pospi
pospi / fix-wpmu-permastruct.php
Created December 5, 2013 04:41
Remove forced `/blog/` prefix added to main site permastruct in Wordpress multisite environments
<?php
global $WPMUPermastructFix;
$WPMUPermastructFix = new MultisitePermastructFix();
class MultisitePermastructFix
{
public function __construct()
{
// start the checking process for main multisite blog. Will strip forced '/blog/' from the start.
@pospi
pospi / placeholder-shim.js
Created November 4, 2013 09:50
Simple placeholder shim for IE. Functions slightly unlike browser placeholders in that the placeholder is removed immedately upon focus. To re-apply or activate elements added to the DOM post-render, simply call `.blur()` on them.
function initPlaceholderCompat()
{
var test = document.createElement('input'),
placeholderSupport = 'placeholder' in test;
if (placeholderSupport) {
return;
}
$(document).on('focus', '[placeholder]', function() {
@pospi
pospi / get-file-ext.php
Created September 24, 2013 01:59
Snippet to get the extension of a file with PHP in the fastest manner possible.
<?php
function extname($path)
{
return substr($path, strrpos($path, '.') + 1);
}