Skip to content

Instantly share code, notes, and snippets.

View koss-lebedev's full-sized avatar

Konstantin koss-lebedev

View GitHub Profile
@koss-lebedev
koss-lebedev / profile_attribute_provider.rb
Created February 6, 2017 16:05
Code samples for Medium article
class ProfileAttributeProvider
def initialize(model)
@model = model
end
def call
ProfileField.all.map do |field|
ActiveDynamic::AttributeDefinition.new(field.name, field.datatype)
end
// @flow
const isStringEmpty = (str?: string) => {
return str && str.trim() !== ""
}
const first = isStringEmpty(null)
const second = isStringEmpty("")
const third = isStringEmpty("test")
// @flow
const isStringEmpty = (str?: string): boolean => {
return Boolean(str && str.trim() !== "")
}
const first = isStringEmpty(null)
const second = isStringEmpty("")
const third = isStringEmpty("test")
// @flow
const SIZE = Object.freeze({
LARGE: "large",
MEDIUM: "medium",
SMALL: "small"
})
type ISize = $Values<typeof SIZE>
// @flow
export type IProps = {|
+title: string,
+description?: string,
|}
class Post extends React.Component<IProps, {}> {
componentDidMount() {
// @flow
const SIZE = Object.freeze({
LARGE: "large",
MEDIUM: "medium",
SMALL: "small"
})
type ISize = $Values<typeof SIZE>
// @flow
const SIZE = /*::Object.freeze(*/{
LARGE: "large",
MEDIUM: "medium",
SMALL: "small"
}
}/*::)*/
type ISize = $Values<typeof SIZE>
FILES_WITHOUT_FLOW="$(grep -r --include=\*.js -L "@flow" src)"
FILES_COUNT=$(echo $FILES_WITHOUT_FLOW | wc -w)
if [ $FILES_COUNT -ne 0 ]
then
echo "Following files are missing @flow annotation:"
echo $FILES_WITHOUT_FLOW | tr " " "\n"
exit 1
fi
defmodule AdventOfCode.Day01 do
def solve(part) when part == :one do
nums = parse_input()
init = delta(Enum.at(nums, 0), Enum.at(nums, -1))
Enum.chunk_every(nums, 2, 1, :discard)
|> Enum.reduce(init, fn([a, b], acc) ->
acc + delta(a, b)
end)
end
import React from 'react'
import { ThemeProvider } from 'styled-components'
import theme from 'styles/theme'
const App = () => (
<ThemeProvider theme={theme}>
/* your components */
</ThemeProvider>
)