Skip to content

Instantly share code, notes, and snippets.

@aravindet
aravindet / fiberify.js
Last active June 11, 2019 07:17
Fiberify: Do for any recursive algorithm what React did with React Fiber.
/*
Lets take any run-of-the-mill recursive algorithm, like factorial:
const factorial = n => (n <= 1) ? 1 : n * factorial(n - 1);
We want to break this computation up and do it during idle time,
yielding to the browser when there's high priority stuff to do like
handling events or painting the scren.
*/

Currently (March 2019) IE11 still needs to be supported, and this requires async/await to be transpiled. Babel's built-in path is to transform async-to-generator and use regenerator-runtime, which adds a significant bundle size penalty.

It would be preferable to transpile async/await to a Promise chain. There are several projects:

  • Kneden which is incomplete and seems abandoned
  • rpetrich's transform turns into a callback pyramid and not a promise chain
  • fast-async which focuses on runtime performance and not bundle size.

Keybase proof

I hereby claim:

  • I am aravindet on github.
  • I am aravindet (https://keybase.io/aravindet) on keybase.
  • I have a public key ASAD2M9v4IENHsTyWuQavGKDi5Jp6bvK-mJJZ38Di7g4WAo

To claim this, I am signing this object:

@aravindet
aravindet / mrt.json
Last active May 26, 2017 07:08
Singapore MRT Data
{
"stations": {
"dhoby_ghaut": {
"name": "Dhoby Ghaut",
"lat": 1.298593,
"lon": 103.845909
},
"bras_basah": {
"name": "Bras Basah",
"lat": 1.296931,
@aravindet
aravindet / jsoncat.md
Last active February 16, 2024 13:08
PostgreSQL JSON Concatenation Operator

Postgres lacks convenient operators for modifying JSON or JSONB values. A common operation one might want to do is to change one property in a JSON column across multiple rows, like:

UPDATE example SET json_col = json_col || '{ "prop": true }'::jsonb WHERE <conditions>;

The || operator is the natural choice for this because it is also used for array and jstore concatenation in Postgres.

This short PLV8 function adds the JSON concatenation operator. It is significantly more powerful than the array and hstore counterparts, and are capable of:

@aravindet
aravindet / selenium-webdriver-js-api.md
Last active September 11, 2022 00:45
A list of functions in Selenium WebDriver

After spending hours trying to find a half-decent API reference for the Selenium WebDriver JS (NodeJS) API, I resorted to examining the object. Properties of the driver object:

{
	controlFlow: [Function],
	schedule: [Function],
	getSession: [Function],
	getCapabilities: [Function],
	getCapability: [Function],
	quit: [Function],

actions: [Function],

@aravindet
aravindet / jquery.fixinview.js
Last active December 30, 2015 08:49
Ensure that chosen elements remain visible when the page scrolls. Elements appear to dock and undock from the window edges in a natural way.
jQuery.fn.fixInView = function() {
var lastTop = 0,
columns = this,
$ = jQuery;
function reposition() {
var top = $(window).scrollTop(),
height = $(window).height(),
up = lastTop > top;

Askabt API documentation

Askabt creates chat rooms where users can connect from the Askabt widget (embedded on your site or app), as well as from their Gmail chat, when they're not using your site or app. This document describes how you can build applications that use Askabt to create chat communities within your app.

Contents