Skip to content

Instantly share code, notes, and snippets.

View tryggvigy's full-sized avatar
🌚
Web developer at Spotify working on Web Player and Desktop clients

Tryggvi Gylfason tryggvigy

🌚
Web developer at Spotify working on Web Player and Desktop clients
  • Spotify
  • Stockholm, Sweden
View GitHub Profile
// @flow
type Iteratee<T> = Array<string> | {[key: string]: T} | string
// Try and fix this
type Iteratee$Weak<T> = Array<string> | {[key: string]: T} | string | Function
type Collection<T> = Array<T> | {[key: string]: T}
declare module 'lodash' {
/**
@tryggvigy
tryggvigy / lodash.js
Last active May 24, 2016 00:09
lodash array methods type specifications
// @flow
type Iteratee<T> = Array<string> | {[key: string]: T} | string
// Try and fix this
type Iteratee$Weak<T> = Array<string> | {[key: string]: T} | string | Function
type Collection<T> = Array<T> | {[key: string]: T}
declare module 'lodash' {
declare var VERSION: string
@tryggvigy
tryggvigy / flow_examples.md
Last active December 12, 2016 23:05
Flow playground links for provided example

Note

https://flowtype.org/try is broken since the flow team pushed v0.36.0 three hours ago. 😕 I filed an issue here: facebook/flow#3003 To run any of the below examples, alter the version dropdown in to top right to v0.36.0

countdownToChristmas

Flow can actually infer the parameter and return types of the function: https://flowtype.org/try/#0GYVwdgxgLglg9mABBO4oBM4HcwBU4DCAFgE4wDOUAtgIbkAU6NUApgJSIDeAUIsgpURMAnuQAyLYFEQBeRACYALIgC0Q5i269EMYIkY1REqYgB8iAAwcefPiRZQQJJAAMAJJxHjJUAL7rRRFgAG2DEYjJKWnIAQhdtX25E7hQwQSZWWUQwFixEABENejYAOgBzB0LWYpTUMAxsPEJSCmo6A1ZSqDgAVQAHPpYSAjoWYqA

@tryggvigy
tryggvigy / dropdown.md
Last active September 15, 2017 13:30
Useful saved replies, view raw to copy markup. These are nice to have in your https://github.com/settings/replies

Dropdown

The markup

Title

  • list
  • with
    • nested
    • items
@tryggvigy
tryggvigy / day1.ml
Created December 1, 2017 21:00
Advent Of Code - Day 1
open Core.Std
let solveCaptcha digits =
let rec loop ls sum = match ls with
| hd::[] when (List.hd_exn digits) = hd -> sum + hd
| hd::sd::tl when hd = sd -> loop (sd::tl) (sum + hd)
| hd::tl -> loop tl sum
| _ -> sum
in
loop digits 0
@tryggvigy
tryggvigy / Card.js
Created January 9, 2018 21:15
react bem
import React, { Component } from 'react';
class Card extends Component {
render() {
return (
<div className = "Card">
<div style= {{backgroundColor : this.props.color}}className = "Card__title-container">
<h6 className = "Card__title">
@tryggvigy
tryggvigy / main.js
Created January 9, 2018 21:24
More components!
import React, { Component } from 'react';
import data from '../../data/data'
import Header from './header';
import EducationList from './EducationList';
import SkillList from './SkillList';
class Main extends Component {
@tryggvigy
tryggvigy / krass.js
Created January 10, 2018 23:33
Krass
const users = [<User name="Fannar"/>, <User name="Tryggvi"/>]
before
<div>
{users.map((user, index) => <User key={index} name={user.name} />)}
</div>
after
header.all: 'جميعها بجوار {0}'
header.popular: 'حفلات موسيقية شعبية بجوار {0}'
header.near_you: بجوارك
header.near_location: 'بجوار {0}'
@tryggvigy
tryggvigy / withRetries.js
Last active March 6, 2020 18:18
Promise retries with exponential backoff
// paste this in any JS REPL to see the execution!
// Note that the fakeAPI is simulated to be flaky so try executin this a few times
// to see both the success and failure case
(() => {
/**
* Wrap a promise API with a function that will attempt the promise over and over again
* with exponential backoff until it resolves or reaches the maximum number of retries.
* - First retry: 500 ms + <random> ms
* - Second retry: 1000 ms + <random> ms
* - Third retry: 2000 ms + <random> ms