Skip to content

Instantly share code, notes, and snippets.

View maticzav's full-sized avatar
🎉
Keep moving forward!

Matic Zavadlal maticzav

🎉
Keep moving forward!
View GitHub Profile
@maticzav
maticzav / main.elm
Created July 10, 2016 09:30
Flatten 2D list in Elm
import List exposing (..)
flatten2D : List (List a) -> List a
flatten2D list =
foldr (++) [] list
-- SAMPLE
flatten2D [[1,2],[3,4],[1,1]] == [1,2,3,4,1,1]
@maticzav
maticzav / main.elm
Last active January 23, 2017 10:55
Elm - get only one element of value from list
unique : List a -> List a
unique list =
case list of
[] ->
[]
x :: [] ->
x :: []
x :: xs ->
@maticzav
maticzav / api
Created September 8, 2016 18:44
####<title>
----
**URL**
<url>
**Methods**
`<method>`|`<method>`
**Data Params**
<body>
**Success Response**
<json_resp>
@maticzav
maticzav / State.elm
Created November 29, 2016 15:33
Allows you to send new state to JS every time state is changed in Elm program.
withOnStateChangeSub : (model -> Cmd msg) -> (msg -> model -> ( model, Cmd msg )) -> msg -> model -> ( model, Cmd msg )
withOnStateChangeSub statePort update msg model =
let
( updatedModel, cmd ) =
update msg model
updatedCmd : Cmd msg
updatedCmd =
if updatedModel == model then
@maticzav
maticzav / today.elm
Created January 22, 2017 21:36
Elm - get beginning of the day from epoch time
import Time exposing (Time)
-- 2017-01-22T17:18:02.921Z -> 2017-01-22T00:00:00.000Z
today : Time -> Time
today time =
time - (toFloat <| rem (round time) (round <| 24.0 * Time.hour))
@maticzav
maticzav / Main.elm
Created January 23, 2017 10:44
Elm - get one before last in list
getOneBeforeLast : List a -> Maybe a
getOneBeforeLast list =
case list of
[] -> Nothing
a :: _ :: [] -> Just a
_ :: a -> getOneBeforeLast a
-- getOneBeforeLast [1,2,3,4,5] == [4]
#1
-- src/
-- users/
-- model.js
-- actions.js
-- views.js
-- exams/
-- votes/
-- requests/
@maticzav
maticzav / .envrc
Created October 13, 2017 15:34
direnv - .envrc production/dev config
#!/bin/bash
unset FOO
echo "env: $NODE_ENV"
if [ "$NODE_ENV" == "production" ]
then
export FOO=qux
else
"dependencies": {
"apollo-client-preset": "^1.0.3",
"expo": "^22.0.2",
"graphql": "^0.11.7",
"graphql-tag": "^2.5.0",
"react": "16.0.0-beta.5",
"react-apollo": "^2.0.1",
"react-native": "^0.49.5",
"react-native-camera": "^0.12.0",
"styled-components": "^2.2.3"
import fetch from 'isomorphic-fetch'
export const uploadFile = file => {
const data = new FormData()
data.append('data', file)
return fetch(GRAPHCOOL_FILE_URL, {
method: 'POST',
body: data,
credentials: 'same-origin'