Skip to content

Instantly share code, notes, and snippets.

@pygy
pygy / PureLPeg.lua
Last active December 15, 2015 20:40
-- A more complete version is now available here:
-- https://github.com/pygy/LuLPeg
-- PureLPeg.lua
-- a WIP LPeg implementation in pure Lua, by Pierre-Yves Gérardy
-- released under the Romantic WTF Public License (see the end of the file).
-- Captures and locales are not yet implemented, but the rest works quite well.
-- UTF-8 is supported out of the box
--
@pygy
pygy / lpeg-brief.md
Last active December 16, 2015 20:59

Brief introduction to LPEG

LPEG is a library for operating on patterns. It is not an alternative to the Lua string library, but it can be used to implement libraries rather like the string library instead of doing it directly in C.

Some words mean very specific things to LPEG.

##### string
A Lua string, consisting of an arbitrary sequence of bytes. On many systems, one could say "characters" instead.
@pygy
pygy / gist:7034063
Created October 17, 2013 23:22
SocketStream grunt log
This file has been truncated, but you can view the full file.
Running "jshint:server" (jshint) task
Linting test/fixtures/project/app.js ...ERROR
[L13:C3] E007: Missing "use strict" statement.
res.serve('main');
Linting test/fixtures/project/app.js ...ERROR
[L25:C12] W116: Expected '===' and instead saw '=='.
if (ss.env == 'production') ss.client.packAssets();
Linting test/fixtures/project/app.js ...ERROR
[L25:C29] W116: Expected '{' and instead saw 'ss'.
if (ss.env == 'production') ss.client.packAssets();
function innerCurry(f, args, context) {
return f.bind.apply(f, [context].concat([].slice.call(args)))
}
function add(a, b, c) {
if (arguments.length < 3) return innerCurry(add, arguments)
return a + b + c
}
add(1).lenght === 2
@pygy
pygy / what-forces-layout.md
Created February 9, 2016 23:35 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@pygy
pygy / mithrilRouter.js
Last active March 6, 2016 00:50
The Mithril router extracted for standalone use.
// The Mithril router extracted to work standalone.
// as a commonJS module.
// the effector must be a function that accepts a DOM node
// (insertion point) and a component, like Mithril;s `m.mount`
// This was done by modifying the code as little as possible
// but the result will need a bit more polish to become universally
// useful...
// The MIT License (MIT)
atrules:
@keyframes: bare -webkit-
@viewport: -ms-
@document:
functions:
linear-gradient(): bare -ms- -webkit-
calc(): bare -webkit-
element():
cross-fade():
@pygy
pygy / README.md
Created January 31, 2017 17:00
Mithril v1 shallow component

Mithril components are diffed wholesale.

m.render(elt, m(Foo))

followed by

m.render(elt, m(Bar))
var c = require("compose-regexp")
function normalize(matcher) {
if (typeof matcher === 'function') return matcher
if (({}).toString.call(matcher) === '[object Object]') return grammar(matchers)
var flags = 'g'
if (matcher instanceof RegExp) flags += matcher.flags.replace('g', '')
matcher = c.flags(flags,
c.either(
matcher,
/()/
<!doctype html>
<title>XRegExp fast-fake-y benchmarks</title>
<table><tr><td>
<div id="log-after">Testing XRegExp 3.1.1-fast-fake-y.<br>Sit back and relax. This might take a while.<br><br>Constructor with short pattern:<br>XRegExp with pattern cache flush x 88,916 ops/sec ±2.24% (82 runs sampled)<br>XRegExp x 834,869 ops/sec ±1.08% (81 runs sampled)<br>XRegExp.cache x 38,821,522 ops/sec ±1.93% (82 runs sampled)<br>RegExp x 5,654,331 ops/sec ±1.68% (81 runs sampled)<br>Fastest is XRegExp.cache<br><br>Constructor with medium pattern:<br>XRegExp with pattern cache flush x 32,278 ops/sec ±1.20% (83 runs sampled)<br>XRegExp x 856,503 ops/sec ±1.48% (79 runs sampled)<br>XRegExp.cache x 38,742,523 ops/sec ±0.66% (82 runs sampled)<br>RegExp x 5,679,163 ops/sec ±2.44% (80 runs sampled)<br>Fastest is XRegExp.cache<br><br>Constructor with long pattern:<br>XRegExp with pattern cache flush x 1,211 ops/sec ±1.01% (80 runs sampled)<br>XRegExp x 484,537 ops/sec ±0.98% (81 runs sampled)<br>XRegExp.cache x 38,776,122 ops/sec ±