Skip to content

Instantly share code, notes, and snippets.

View ivan-demchenko's full-sized avatar

Ivan Demchenko ivan-demchenko

View GitHub Profile
@ivan-demchenko
ivan-demchenko / package.json
Created October 15, 2019 19:37
Rollup for React with TypeScript and SVG icons
{
"devDependencies": {
"@svgr/rollup": "^4.3.3",
"@types/react": "^16.9.7",
"@types/react-dom": "^16.9.2",
"rollup": "^1.24.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-filesize": "^6.2.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.2",
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Merge Linked Lists">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
@ivan-demchenko
ivan-demchenko / com.user.automaticbackups.plist
Last active October 28, 2018 05:45
Automatic backup with notifications and rsync
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.idemchenko.automaticbackups</string>
<key>StandardOutPath</key>
<string>/tmp/autoBackup.stdout</string>
@ivan-demchenko
ivan-demchenko / functions.fish
Last active June 6, 2018 03:58
fish git functions
// ~/.config/fish/functions/gb.fish
function gb
set _curr_git_branch (git branch ^/dev/null | grep \* | sed 's/* //')
echo ">>> Rebasing $_curr_git_branch onto master <<<"
gco master
gpl
gpl origin master
gco $_curr_git_branch;
@ivan-demchenko
ivan-demchenko / recursive-monadic-fn.js
Last active October 23, 2017 01:16
Async recursion
const daggy = require('daggy');
const Task = require('data.task');
const path = require('path');
const fs = require('fs');
const { sequence } = require('ramda');
// type Entity
// = File String
// | Dir String (List Entity)
const Entity = daggy.taggedSum('Entity', {
@ivan-demchenko
ivan-demchenko / functors.ts
Last active March 28, 2017 07:27
This is my experiment to implement a functor type class using TypeScript
interface Functor<A> {
fmap<B>(f: (x: A) => B): Functor<B>
}
const fmap = <A, B>(f: (x: A) => B) => (fa: Functor<A>): Functor<B> => fa.fmap(f);
//=== String
interface String extends Functor<String> {
}
@ivan-demchenko
ivan-demchenko / quickStart.js
Last active September 12, 2016 07:26
Two most important functions for functional js
/**
* Here are two essential functions for functional style in JavaScript.
* Unfortunately, functions are not curried by default in JS.
* Also, there is no function composition operator in JS.
* Thus, we have to implement these on our own.
**/
const comp = (...fns) => (...args) =>
fns.reduceRight((res, fn) => fn(...[].concat(res)), args);
const curryN = (num, fn) => (...args) =>
@ivan-demchenko
ivan-demchenko / preloader-or-image.js
Last active July 24, 2017 02:49
Show the pre-loader when image loading takes more than X milliseconds
// just a helper
var $ = document.querySelector.bind(document);
// "show me the next image" button
var nextImage = Bacon.fromEvent($('#next'), 'click');
// this button simulated "onload" event for the img tag
var img = Bacon.fromEvent($('#loaded'), 'click').map(_ => 'image.jpg.' + Math.random());
// We need a stream that will be ended either on its own or by another stream.
// This is the implmenetation of some of the lamdas from lamda calculus
// https://en.wikipedia.org/wiki/Lambda_calculus
console.clear();
const log = function(x) {
console.log('log: ' + x);
return x;
}
// Boolean:
@ivan-demchenko
ivan-demchenko / lazy-take-while-list.js
Created September 20, 2015 16:27
Lazy list comprehension using generator
// Inspired by Haskell's `takeWhile (<10000) $ map (^3) [1..]`
let nextVal = (x) => x.next().value;
function* mList(x = 0) {
while(1) yield x++;
}
function* map(fn, list) {
while(1) {
yield fn(nextVal(list));