Skip to content

Instantly share code, notes, and snippets.

View iliyan-trifonov's full-sized avatar

Iliyan Trifonov iliyan-trifonov

View GitHub Profile
@iliyan-trifonov
iliyan-trifonov / README.md
Created October 15, 2017 16:50
Cycle.js: text input, a button to click and Enter key press action

When the button is clicked or the Enter key is pressed while typing in the input, the text below is updated. The text below shows the text from the input as well as if the information is updated by pressing Enter or clicking on the button.

@iliyan-trifonov
iliyan-trifonov / main.js
Created October 15, 2017 09:46
Cycle.js: text input and a button, latest text is assigned to result on button click
import {run} from '@cycle/run';
import {makeDOMDriver, div, button, br, input} from '@cycle/dom';
import xs from 'xstream';
import sampleCombine from 'xstream/extra/sampleCombine';
function main (sources) {
const click$ = sources.DOM.select('.button').events('click').startWith(false);
const input$ = sources.DOM.select('.input').events('input');
const text$ = input$.map(ev => ev.target.value).startWith('');
const combined$ = click$.compose(sampleCombine(text$));
@iliyan-trifonov
iliyan-trifonov / App.elm
Created September 2, 2016 17:25
Convert a for loop to get the min and max values from a list to Elm code
-- original JS code
-- var list = [ 3, 42, 73, 2 ];
-- var min = list[0], max = list[0];
-- for (var i = 0; i < list.length; i++) {
-- min = Math.min(min, list[i]);
-- max = Math.max(max, list[i]);
--}
-- we will use Html.text to show the result
import Html exposing (text)
@iliyan-trifonov
iliyan-trifonov / App.elm
Created September 2, 2016 13:28
Sum 10 numbers in a JS for loop -> converted to Elm with recursion
-- original JS code
--var result = 0;
--for ( var i = 0; i <= 10; i++) {
-- result += i;
--}
-- we will use Html.text to show the result
import Html exposing (text)
-- let's call the function `sumMe`
@iliyan-trifonov
iliyan-trifonov / App.elm
Created September 1, 2016 20:55
Solution 3 for Project Euler problem 1 written in Elm
-- we will show the result with a single html text node
import Html exposing (text)
-- let's call the function euler1 and say it receives a single Int param and returns a single Int param
euler1 : Int -> Int
euler1 num =
-- no recursion this time, only lists
let
-- create a list with numbers from 1 to num - 1
list = [1..num-1]
@iliyan-trifonov
iliyan-trifonov / App.elm
Created September 1, 2016 20:47
Solution 2 for Project Euler problem 1 written in Elm
-- we will show the result with a single html text node
import Html exposing (text)
-- let's call the function euler1 and say it receives two Int params and returns a single Int param
euler1 : Int -> Int -> Int
euler1 num numMax =
-- break point of the recursion is when num increased to numMax
if num == numMax then
0
else
@iliyan-trifonov
iliyan-trifonov / App.elm
Last active September 1, 2016 20:43
Solution 1 for Project Euler problem 1 written in Elm
-- we will show the result with a single html text node
import Html exposing (text)
-- let's call the function euler1 and say it receives a single Int param and returns a single Int param
euler1 : Int -> Int
euler1 num =
-- break point of the recursion is when num is 0
if num == 0 then
0
else

Keybase proof

I hereby claim:

  • I am iliyan-trifonov on github.
  • I am iliyan (https://keybase.io/iliyan) on keybase.
  • I have a public key whose fingerprint is E823 F836 CB93 1FC8 76C5 6792 C71F 8218 E912 BE87

To claim this, I am signing this object: