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 / color.ts
Last active April 22, 2024 02:41
RGB color hex to lightness
// based on https://stackoverflow.com/a/56678483/65387
type RGB = [r: number, g: number, b: number]
const UNK = 255 / 2
/**
* @param hex RGB hex string like "#CCCFDB"
* @returns RGB tuple in [0-255]
*/
@mnpenner
mnpenner / mode-mysql.js
Created April 16, 2013 02:14
MySQL mode for Ace editor. Based on existing pgsql mode with MySQL keywords and functions.
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
@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 {
<!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>
@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 / 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;
}
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 / screenshot.js
Last active December 5, 2019 16:08
Save a screenshot with selenium-webdriver for JavaScript
var webdriver = require('selenium-webdriver');
var fs = require('fs');
var driver = new webdriver.Builder().build();
webdriver.WebDriver.prototype.saveScreenshot = function(filename) {
return driver.takeScreenshot().then(function(data) {
fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''), 'base64', function(err) {
if(err) throw err;
});
@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,