Skip to content

Instantly share code, notes, and snippets.

@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 / get-hz-rdb-table.js
Created August 4, 2016 05:31
Curryable function to load `r.table` objects for horizon.io collections
const r = require('rethinkdb');
const { curry } = require('ramda');
module.exports = curry(function* (rdbConn, projectName, collectionName) {
const table = yield r.db(`${projectName}_internal`).table('collections').get(collectionName).getField('table').run(rdbConn);
return r.db(projectName).table(table);
});
@pospi
pospi / nodejs-global-module-includes.js
Last active June 2, 2016 00:10
nodejs module system hack to add a module's include paths to global include paths.
// Usage: from your entrypoint script file or other 'global' module of interest:
// require('nodejs-global-module-includes')(module);
var Module = require('module');
export default function setModuleIncludePathGlobal(globalModule) {
var globalPaths = globalModule.paths;
var oldPathHandler = Module._nodeModulePaths;
Module._nodeModulePaths = function(from) {
@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 / 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);
}
@pospi
pospi / detect-numeric-arrays.php
Created September 24, 2013 01:58
Determine if a PHP array is numeric in the quickest way available.
<?php
function isNumeric($arr)
{
return array_keys($arr) !== range(0, count($arr) - 1);
}
@pospi
pospi / string-bytelen.php
Created September 24, 2013 01:56
Get reliable byte length of a string in PHP. Works around an issue where the multibyte string extension can be configured to shadow strlen().
<?php
/**
* Works around an issue where the multibyte string extension
* can be configured to shadow strlen(), and no longer returns pure
* bytelength.
* @param string $str string to get byte length of
* @return int
*/
function bytelen($str)
{
@pospi
pospi / font-list-bullets.css
Created September 24, 2013 01:18
List bullets using font characters (best used with icon fonts!). Supported in everything except IE6 & 7, with graceful fallback.
ul {
list-style:none;
padding: 0 0 0 2em; /* padding includes space for character and its margin */
/* IE7 and lower use default */
*list-style: disc;
*padding: 0 0 0 1em;
}
ul li:before {
content: '\25BA';
@pospi
pospi / fontsize-reset.less
Last active December 23, 2015 18:59
Setup base font size reliably with CSS. Creates any baseline font size you wish to base your em units off.
@BASE_FONT_SIZE = 16;
@BASE_LINE_HEIGHT = 1.5;
// consistent base font size & line height (16px)
html {
font-size: 100%;
*font-size: 16px;
line-height: @BASE_LINE_HEIGHT;
}