Skip to content

Instantly share code, notes, and snippets.

@nite
nite / debounce.R
Last active March 23, 2017 17:10
# from https://gist.github.com/jcheng5/6141ea7066e62cafb31c
# Returns a reactive that debounces the given expression by the given time in
# milliseconds.
#
# This is not a true debounce in that it will not prevent \code{expr} from being
# called many times (in fact it may be called more times than usual), but
# rather, the reactive invalidation signal that is produced by expr is debounced
# instead. This means that this function should be used when \code{expr} is
# cheap but the things it will trigger (outputs and reactives that use
# \code{expr}) are expensive.
@nite
nite / curry.py
Last active May 29, 2017 21:36
A simple curry function in python
def curry(func):
def f(*args):
outerArgs = args
next = lambda *args : f(*args, *outerArgs)
next.value = lambda: func(args)
return next
return f
add = curry(sum)
@nite
nite / kvp.js
Last active January 5, 2018 09:17
Serialise input as key-value pair string, eg. for human-readable logs.
/**
* Serialise input as key-value pair string, eg. for human-readable logs.
*
* @param {any} body
* @param {number} nest
* @param {string} delimiter
* @param {string} arrayDelimiter
* @param {boolean} nested
* @returns {string}
*/
@nite
nite / grid-selection.directive.ts
Last active August 15, 2018 16:47
Typescript ag-Grid Range selection directive which selects & highlights rows for any selected cell & emits a 'rangeSelectionRowsChanged' with a rows property of selected rows.
import {Directive, EventEmitter, Output} from '@angular/core';
import {AgGridNg2} from 'ag-grid-angular';
import {GridApi} from 'ag-grid';
/***
* Range selection directive which selects & highlights rows for any selected cell
* (ctrl+click for multiple ranges) and emits a 'rangeSelectionRowsChanged' with a
* rows property of selected rows.
*
* NOTE: this only currently supports client-side grids.
@nite
nite / plotly_crossfilter.py
Last active January 31, 2024 15:13
Plotly Dash Crossfilter
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
from dash.dependencies import Output, Input, State
import dash_table_experiments as dt
from plotly.graph_objs.layout import Margin
app = dash.Dash(static_folder='static')
@nite
nite / js.ipynb
Last active April 1, 2019 21:40
Jupyter Notebook with client-side javascript interactive data visualisation in d3 & Plotly plots, plus a http fetch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nite
nite / index.html
Created October 21, 2019 22:04
Interactive Particle Logo
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>ParticleSlider</title>
</head>
<body id="particle-slider">
<div class="slides">
<div id="first-slide" class="slide"
style="width: 100%; height 100%"
data-noise="100"
@nite
nite / AgGridWrapper.tsx
Created March 5, 2020 21:06
ag-grid wrapper with persistence of grid column & filter state in localStorage
import {ColDef, ColGroupDef, ColumnApi, GridApi} from 'ag-grid-community';
import {AgGridReact} from 'ag-grid-react';
import {AgGridReactProps} from 'ag-grid-react/lib/agGridReact';
import {functions, isEqual, omit} from 'lodash';
import log from 'loglevel';
import React, {useState} from 'react';
import useDeepCompareEffect from 'use-deep-compare-effect'
const gridStateChangeEvents = ['model', 'displayedColumnsChanged'];
@nite
nite / toObservable.ts
Created March 4, 2021 11:51
wrap function in mobx computed() and convert to rxjs observable
import { Observable } from 'rxjs';
import { computed, IValueDidChange } from 'mobx';
import isNil from 'lodash/isNil';
import omit from 'lodash/omit';
import { IEqualsComparer } from 'mobx/lib/internal';
interface ToObservableOptions<T> {
initial?: boolean;
equals?: IEqualsComparer<T>;
}
@nite
nite / pivot.ts
Last active July 20, 2021 22:14
typescript pivot
function pivot(meltedData, pivotCols: string[], varName: string, valueName: string) {
const groups = {};
for (const d of meltedData) {
const key = pivotCols.map((k) => d[k]).join('|');
const group = groups[key];
groups[key] = {
...(group ? group : fromPairs(pivotCols.map((k) => [k, d[k]]))),
[d[varName]]: d[valueName],
};