Skip to content

Instantly share code, notes, and snippets.

// This is evolved into j2c: a JavaScript to CSS compiler
// see https://github.com/pygy/j2c
@pygy
pygy / mithril.login_redirect.md
Last active March 23, 2019 16:51
Mithril Login redirect by Barney Carol

Taken from https://gitter.im/lhorie/mithril.js?at=553bdd1763c55be30636a16b in case it disappeared.

@barneycarol said:

[...] FWIW you can overcome a lot of apparent limitations in m.route by reinitialising m.route when things change

@tobscure said:

interesting, examples?

@barneycarol said:

Well I use it when authentication status changes

@pygy
pygy / widget.js
Last active August 29, 2015 14:21 — forked from gilbert/widget.js
Mithril + j2c
Widget = {
styles: j2c.scoped({
title: {
font_size: '3rem',
"&:before":{
color: "#888",
content: "#"
}
},
content: {
/*\
For now, back to the stable if less featureful v4
TODO: implement http://stackoverflow.com/questions/4845762/onload-handler-for-script-tag-in-internet-explorer
for old ie compatiblity (where script.onload doesn't fire).
`{loading, element} = mithrilLoader(libs::Arrary [, m::mithril])`
where `libs` is an array of strings and array:

Broad summary:

  • Elections are on Sunday 5th, July.

  • This is the first time an e-voting system is used in Buenos Aires city.

  • Researchers and IT professionals had been warning about potential issues with the way the system works (short summary at the end).

  • Government officials have said on-record that the machines are only "printers with no memory". There is video evidence that the machines are in fact standard PCs running Ubuntu. USB and VGA ports are located behind a lid on the side. See videos here: https://storify.com/mis2centavos/el-sistema-de-voto-electronico-usado-en-caba

@pygy
pygy / color-conversion-algorithms.js
Last active September 10, 2015 07:14 — forked from mjackson/color-conversion-algorithms.js
RGB, HSV, and HSL color conversion algorithms in JavaScript
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
* @param Number r The red color value
* @param Number g The green color value
* @param Number b The blue color value
* @return Array The HSL representation
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)
@pygy
pygy / cancelPromise.md
Last active May 9, 2024 13:27
You can already cancel ES6 Promises

The gist: by having a Promise adopt the state of a forever pending one, you can suspend its then handlers chain.

Promise.pending = Promise.race.bind(Promise, [])

let cancel

new Promise(function(fulfill, reject) {
  cancel = function() {fulfill(Promise.pending())}
  setTimeout(fulfill, 1000, 5)