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
# prisma.yml
# Name of our project
service: graphql-server-file-upload-example
# Creates a development cluster on your local Docker instance
stage: dev
cluster: local
# Paths to our datamodel files
# database/datamodel/types.graphql
type File {
id: ID! @unique
name: String!
size: Int!
secret: String! @unique
contentType: String!
createdAt: DateTime!
updatedAt: DateTime!
// src/modules/fileApi.ts
import * as multiparty from 'multiparty'
let form = new multiparty.Form()
form.on('part', async function(part) {
if (part.name !== 'data') {
return
}
// src/index.ts
import { S3 } from 'aws-sdk'
// Creates S3 client
const s3client = new S3({
accessKeyId: process.env.S3_KEY,
secretAccessKey: process.env.S3_SECRET,
params: {
Bucket: process.env.S3_BUCKET
}
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'
"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"
@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
#1
-- src/
-- users/
-- model.js
-- actions.js
-- views.js
-- exams/
-- votes/
-- requests/
@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]
@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))