Skip to content

Instantly share code, notes, and snippets.

View tarasowski's full-sized avatar
:electron:

Dimitri (Dimi) Tarasowski tarasowski

:electron:
View GitHub Profile
@tarasowski
tarasowski / math.md
Last active April 14, 2020 06:18
Math embedding
We couldn’t find that file to show.
@tarasowski
tarasowski / example.js
Last active March 24, 2020 06:29
How to deal w/ side-effects
import { objectivesStore, keyResultsStore, listOKRs, deleteOKR as deleteOKRMutation, updateOKR } from './stores/okrs.js'
import { teamStore, listTeams } from './stores/teams.js'
import { error } from './stores/errors.js'
import { memberStore, listMembers } from './stores/members.js'
import { fork, reject, parallel } from 'fluture'
import { onMount } from 'svelte'
import { pipe, head, filter, maybe, map, prop, sortBy } from './sanctuary.js'
let viewMode
@tarasowski
tarasowski / App.js
Last active March 29, 2019 11:30
React Hooks
import React, { useState, useEffect } from 'react';
import * as S from 'sanctuary'
import {ul, li, a, div, input, button, pre, p} from 'react-hyperscript-helpers'
import axios from 'axios'
import $ from 'sanctuary-def'
const getResult = data =>
S.fromMaybe ([]) (S.gets (S.is ($.Array ($.Object))) (["data", "hits"]) (data))
const value = e =>
@tarasowski
tarasowski / promise-pipeline.js
Last active February 10, 2019 12:57
Avoid using try/catch() with Promise composition
const composeP = (...fns) => x => fns.reduceRight(async (v, f) => f(await v), x)
const db1 = () => Promise.reject('already in db').catch(e => console.error(e))
const db2 = () => Promise.reject('already in db').catch(e => console.error(e))
const db3 = () => Promise.reject('already in db').catch(e => console.error(e))
const db4 = () => Promise.resolve('success, items has been saved')
const myPipeline = composeP(
@tarasowski
tarasowski / transitional-state.js
Created February 8, 2019 06:18
An example how to build up a pipeline with transitional state and side effects
const axios = require('axios')
const composeP = (...fns) => x => fns.reduceRight(async (v, f) => f(await v), x)
const user = {
name: 'Dimitri',
age: 35,
location: 'Berlin',
attributes: {
hair: 'grey',
eyes: 'green',
@tarasowski
tarasowski / sum-recursion.js
Created January 29, 2019 19:28
Calculate sum of an array recursively
const arr = [1, 2, 3]
const sum = arr =>
arr.length === 0
? 0
: arr[0] + sum(Array.prototype.slice.call(arr, 1))
sum(arr) // 6
@tarasowski
tarasowski / vim.sh
Last active February 23, 2019 08:48
Vim commands
## Some other goodies
# :e<space><CR> -> will reload the file you are working in.
# vmap -> is a mapping just for visual mode. That particular mapping is only valid in visual mode.
# nmap -> is a mapping for normal mode. Only available in normal mode. Recursive. It runs the mapped command from vim and the new command that is assigned together.
# nnoremap -> disables recursive key mapping for that map.
## Key comamnds
# <BS> Backspace
# <CR> Enter
# <Enter> Enter
@tarasowski
tarasowski / reverse.js
Created January 27, 2019 15:37
Reverse array
const xs = [1, 2, 3, 4, 5]
const reverse = xs =>
xs.reduceRight((a, c) => a.concat(c), [])
const head = xs => xs[0]
head(
reverse(xs)
@tarasowski
tarasowski / react-hooks.js
Last active January 24, 2019 06:35
Pure function composition, no assignments.
const compose = (...fns) => x => fns.reduceRight((v, f) => f(v), x)
const useState = init =>
([init, (init =>
x =>
useState(init + x))(init)])
const createState = useState =>
useState(3)
@tarasowski
tarasowski / git-branch.md
Last active December 15, 2018 13:47
Working with Git Branches
  1. Creates MyFeature branch off master. Do your work and then
    $ git checkout -b myFeature master

  2. Commit your changes to myFeature branch
    $ git commit -am "Your message"

  3. Now merge your changes to master without a fast-forward
    $ git checkout master
    $ git merge --no-ff myFeature