Skip to content

Instantly share code, notes, and snippets.

@bfunc
bfunc / dataTable.module.js
Created September 8, 2014 13:05
DataTables AngularJS Directive
angular.module('datatable',[])
.controller('DatatableController', ['$scope', '$attrs', '$filter', function ($scope, $attrs, $filter) {
var sEcho = 0;
$scope.openDateTo = function($event,param) {
$event.preventDefault();
$event.stopPropagation();
@bfunc
bfunc / index.html
Last active October 9, 2017 12:14
d3 v4 - detect click coordinates in zoomed area
<!DOCTYPE html>
<html>
<head>
<script src="https://d3js.org/d3.v4.js"></script>
<style>
body {margin: 0 }
svg { background-color: #86B2EB; }
svg circle.old { fill: green; }
svg circle.new { fill: blue; }
@bfunc
bfunc / data.json
Last active October 9, 2017 12:31
d3 v4 - issue - axis Date grid uneven line sizes
[
{
"daystamp": {
"value": "2017-03-01 00:00:00.000"
},
"PL": -13496
},
{
"daystamp": {
"value": "2017-03-02 00:00:00.000"
@bfunc
bfunc / http-request-fetch.js
Last active November 22, 2018 20:23
http request window.fetch() snippet with application/json headers
fetch('http://HOST/api',
{
method: 'post', // 'put'
headers: { 'Accept': 'application/json, text/plain', 'Content-Type': 'application/json' },
body: JSON.stringify( {"User_employee_id":"1","template_id":0,"data":[{"id":1509003681672,"contract":"EuroDollar@SEP18"}]} ),
// cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
// credentials: 'same-origin', // include, same-origin, *omit
// mode: 'cors', // no-cors, cors, *same-origin
// redirect: 'follow', // manual, *follow, error
// referrer: 'no-referrer', // *client, no-referrer
@bfunc
bfunc / ExternalReactApp.js
Last active September 9, 2018 08:05
dynamic load and update ReactDOM tree (need localhost)
class MyCmp extends React.Component {
constructor(props) {
super(props);
this.state = { data: 2000 };
}
render() {
return React.createElement('div', null, [
React.createElement('div', {}, `Agent ${this.props.initValue} ${this.state.data} had arrived `),
]);
@bfunc
bfunc / index.js
Created June 4, 2019 12:13
stats.js gist
var stats = new Stats();
document.body.appendChild(stats.dom);
requestAnimationFrame(function loop() {
stats.update();
requestAnimationFrame(loop)
});
@bfunc
bfunc / es6-generators.js
Last active August 2, 2019 20:02
observable API for synchronous-style async functions
const isPromise = obj => Boolean(obj) && typeof obj.then === 'function';
const next = (iter, callbacks, prev = undefined) => {
const { onNext, onCompleted } = callbacks;
const item = iter.next(prev);
const value = item.value;
if (item.done) {
return onCompleted();
const lessThan = function(end, value) {
return function(value) {
return value < end;
};
}
// 25 alphabet character letters
const lessThan26 = lessThan(26);
const lazyMap = function* (iterable, callback) {
@bfunc
bfunc / machine.js
Last active April 10, 2021 00:12
Generated by XState Viz: https://xstate.js.org/viz
const redditMachine = Machine(
{
id: 'reddit',
initial: 'idle',
context: {
question: 'em',
},
states: {
@bfunc
bfunc / machine.js
Last active April 14, 2021 22:00
Generated by XState Viz: https://xstate.js.org/viz
const wait = ms => new Promise(r => setTimeout(() => r(), ms))
const fetchResource = async ({ url, fakeDelayMs = 0 }) => {
await wait(fakeDelayMs)
return fetch(url).then(res => res.json())
}
const constants = {
MAX_QUESTION_SCORE: 3,
MAX_RETRIES: 15,