Skip to content

Instantly share code, notes, and snippets.

View jongacnik's full-sized avatar

Jon jongacnik

View GitHub Profile
@silo
silo / Browser-detect.js
Created August 24, 2017 08:54
Browser detect
// Opera 8.0+
var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Firefox 1.0+
var isFirefox = typeof InstallTrigger !== 'undefined';
// Safari 3.0+ "[object HTMLElementConstructor]"
var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);
// Internet Explorer 6-11
@rchrd2
rchrd2 / php_cache.php
Created June 3, 2017 22:38
Poor man's php cache. Saves to files. Includes expiry.
<?php
function add_cache($key, $value, $ttl) {
$dir = __DIR__.'/../cache/';
// Remove slashes for security
$filename = $dir . str_replace('/', '', $key);
// Store expiry in first line
$lines = [(string)(time() + (int)$ttl), $value ];
if (!file_exists($dir)) mkdir($dir, 0755, true);
file_put_contents($filename, implode("\n", $lines));
@icebeat
icebeat / createNode
Created March 20, 2017 08:51
Create dom nodes from html string
const createNode = html => new DOMParser().parseFromString(html, "text/html").body.firstChild
const example = createNode(`
<section>
<h1>Hello World</h1>
</section>
`)
/**
* A reset for Kirby’s panel
* Work in progress
*
* Installation
* - Create CSS file inside your site’s assets directory
* - Open config.php and add the following line
* c::set('panel.stylesheet', 'assets/panel.css');
* - Adjust to your liking
*/
@gsanders5
gsanders5 / example.nginx
Last active August 18, 2022 06:20
Automatic nginx virtual subdomains with sub-folders or sub-directories
# Automatic nginx virtual subdomains with sub-folders or sub-directories
#
# Since the original source where I found this code is now offline, I have decided to mirror it here.
# All credit goes to: http://web.archive.org/web/20150307193208/http://www.messaliberty.com/2010/10/automatic-nginx-virtual-subdomains-with-sub-folders-or-sub-directories
#
# Description: In my web root directory I wanted create a folder called photos, and another called
# music using a sftp program. Without manually going back to the config file or to the shell I like to
# be able to access them at photos.nginxdomain.com and music.nginxdomain.com. That is what this config does.
# Redirect visitors from http://nginxdomain.com/ to http://www.nginxdomain.com/
@arianagiorgi
arianagiorgi / README.md
Last active December 14, 2022 01:51
Jittering overlapping GeoJSON points

Jittering GeoJSON points

Problem: You have geometry points that have the same (or nearly same) lat and lon in your GeoJSON/shp file and when you map them they overlap.

Solution: Using Leaflet... You can use the markercluster plugin and spiderfy the cluster. Using MapboxGL... you'll have to add random jitter (slightly change the lat and lon of the overlapping points). This process will take you through how to do that using PostGIS and QGIS.

  1. Get data into PostGIS

  2. You can use the following SQL query to determine what points will need to be jittered. This will depend on what your fields are. In my dataset, some points had the exact same geom (lat/lon) while other had a slightly different lat/lon but the same address. In both cases, I wanted to jitter these points.

@mikesallander
mikesallander / constant-contact-ajax-form.markdown
Created October 22, 2016 16:52
Constant Contact Ajax Form
@iiidefix
iiidefix / .htaccess
Last active June 18, 2023 16:25
A simple classless PHP regex router function
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./router.php/$1 [QSA]
@stramel
stramel / css-var-polyfill.js
Created September 6, 2016 21:48
CSS Variable Polyfill
/*
TODO:
X Maybe account for defaults: color: var(--header-color, blue);
- Verify cross domain working or not (it is working from dropbox)
- Option to wait to apply anything until all <link>s are parsed or inject what we have and update as each <link> returns
- Need to test on a more complex CSS file
- Option to save parsed file in local/session storage so there isn't a delay on additional page loads. Could only do it for links (with URLs to use as keys) and style blocks with IDs of some sort
- Need to test more complex values like rgba(255,0,0,0.5); and something with !important
- Try multiple links
- Local links
@jpwilliams
jpwilliams / regex.js
Last active September 29, 2016 08:14
Simple Markdown Single Regex
// Very simple regex that supports ```big code blocks```,
// `code highlights`, *bold*, _italic_ and ~strikethrough~,
// isolating each group.
/(`{3}([\S\s]+?)`{3})|(`(.+?)`)|(\*(.+?)\*)|(_(.+?)_)|(~(.+?)~)|(\n)|(.+?)/gm