Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mnpenner's full-sized avatar
:octocat:

Mark Penner mnpenner

:octocat:
View GitHub Profile
@mnpenner
mnpenner / startswith_benchmark.php
Last active October 14, 2020 03:10
Various StartsWith implementations
<?php
function substr_startswith($haystack, $needle) {
return substr($haystack, 0, strlen($needle)) === $needle;
}
function preg_match_startswith($haystack, $needle) {
return preg_match('~' . preg_quote($needle, '~') . '~A', $haystack) > 0;
}
$.validator.setDefaults({
onfocusout: function(element, event) {
if(element.tagName === 'TEXTAREA' || (element.tagName === 'INPUT' && element.type !== 'password')) {
element.value = $.trim(element.value);
}
return $.validator.defaults.onfocusout.call(this, element, event);
}
});
@mnpenner
mnpenner / countries.json
Created January 5, 2015 02:58
Timezones
[{"timezones":["Europe\/Andorra"],"code":"AD","continent":"Europe","name":"Andorra","capital":"Andorra la Vella"},{"timezones":["Asia\/Kabul"],"code":"AF","continent":"Asia","name":"Afghanistan","capital":"Kabul"},{"timezones":["America\/Antigua"],"code":"AG","continent":"North America","name":"Antigua and Barbuda","capital":"St. John's"},{"timezones":["Europe\/Tirane"],"code":"AL","continent":"Europe","name":"Albania","capital":"Tirana"},{"timezones":["Asia\/Yerevan"],"code":"AM","continent":"Asia","name":"Armenia","capital":"Yerevan"},{"timezones":["Africa\/Luanda"],"code":"AO","continent":"Africa","name":"Angola","capital":"Luanda"},{"timezones":["America\/Argentina\/Buenos_Aires","America\/Argentina\/Cordoba","America\/Argentina\/Jujuy","America\/Argentina\/Tucuman","America\/Argentina\/Catamarca","America\/Argentina\/La_Rioja","America\/Argentina\/San_Juan","America\/Argentina\/Mendoza","America\/Argentina\/Rio_Gallegos","America\/Argentina\/Ushuaia"],"code":"AR","continent":"South America","name":"Argen
naughty becomes charsets
0x0027 0x005C 0x27 UCS-2 [\] UCS-2BE [\] UCS-2LE [尀] UTF-16 [\] UTF-16BE [\] UTF-16LE [尀]
0x0127 0x015C 0x27 UCS-2 [Ŝ] UCS-2BE [Ŝ] UCS-2LE [封] UTF-16 [Ŝ] UTF-16BE [Ŝ] UTF-16LE [封]
0x0227 0x025C 0x27 UCS-2 [ɜ] UCS-2BE [ɜ] UCS-2LE [専] UTF-16 [ɜ] UTF-16BE [ɜ] UTF-16LE [専]
0x0327 0x035C 0x27 UCS-2 [͜] UCS-2BE [͜] UCS-2LE [尃] UTF-16 [͜] UTF-16BE [͜] UTF-16LE [尃]
0x0427 0x045C 0x27 UCS-2 [ќ] UCS-2BE [ќ] UCS-2LE [射] UTF-16 [ќ] UTF-16BE [ќ] UTF-16LE [射]
0x0527 0x055C 0x27 UCS-2 [՜] UCS-2BE [՜] UCS-2LE [尅] UTF-16 [՜] UTF-16BE [՜] UTF-16LE [尅]
0x0627 0x065C 0x27 UCS-2 [ٜ] UCS-2BE [ٜ] UCS-2LE [将] UTF-16 [ٜ] UTF-16BE [ٜ] UTF-16LE [将]
0x0727 0x075C 0x27 UCS-2 [ݜ] UCS-2BE [ݜ] UCS-2LE [將] UTF-16 [ݜ] UTF-16BE [ݜ] UTF-16LE [將]
0x0827 0x085C 0x27 UCS-2 [࡜] UCS-2BE [࡜] UCS-2LE [專] UTF-16 [࡜] UTF-16BE [࡜] UTF-16LE [專]
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Location to Timezone</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.0.0/normalize.min.css">
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/0.11.0/fetch.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.10.0/lodash.min.js"></script>
<style>
const checkOffset = $.datepicker._checkOffset;
$.extend($.datepicker, {
_checkOffset: function(inst, offset, isFixed) {
if(!isFixed) {
return checkOffset.apply(this, arguments);
}
let isRTL = this._get(inst, "isRTL");
let obj = inst.input[0];
@mnpenner
mnpenner / mysql.js
Last active July 5, 2018 23:21
JoinMonster MySQL Dialect
/* eslint-disable no-restricted-syntax, no-use-before-define */
import _ from 'lodash';
import {log} from '../debug';
import {
interpretForOffsetPaging,
orderColumnsToString,
// interpretForKeysetPaging,
// keysetPagingSelect,
// offsetPagingSelect,
validateCursor,
@mnpenner
mnpenner / package.json
Last active January 3, 2021 22:46
Rollup Plugin: Pug
{
"license": "UNLICENSED",
"dependencies": {
"fastify": "^3.9.2",
"fastify-cookie": "^5.1.0",
"fastify-sensible": "^3.1.0",
"google-auth-library": "^6.1.3",
"lodash": "^4.17.20",
"pug": "^3.0.0",
"pug-runtime": "^3.0.0"
@mnpenner
mnpenner / LazyImg.tsx
Last active February 5, 2022 20:09
Smart-sized image
import {useMemo, useRef} from 'react'
import {useBoundingBox} from '../hooks/useBoundingBox'
import {sortBy} from 'lodash-es'
interface Size {
width: number
height: number
}
interface SrcItem extends Size {