Skip to content

Instantly share code, notes, and snippets.

Konstantin koss-lebedev

Block or report user

Report or block koss-lebedev

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@koss-lebedev
koss-lebedev / profile_attribute_provider.rb
Created Feb 6, 2017
Code samples for Medium article
View profile_attribute_provider.rb
class ProfileAttributeProvider
def initialize(model)
@model = model
end
def call
ProfileField.all.map do |field|
ActiveDynamic::AttributeDefinition.new(field.name, field.datatype)
end
View explitReturnBad.js
// @flow
const isStringEmpty = (str?: string) => {
return str && str.trim() !== ""
}
const first = isStringEmpty(null)
const second = isStringEmpty("")
const third = isStringEmpty("test")
View explicitReturnGood.js
// @flow
const isStringEmpty = (str?: string): boolean => {
return Boolean(str && str.trim() !== "")
}
const first = isStringEmpty(null)
const second = isStringEmpty("")
const third = isStringEmpty("test")
View valueTypeExample.js
// @flow
const SIZE = Object.freeze({
LARGE: "large",
MEDIUM: "medium",
SMALL: "small"
})
type ISize = $Values<typeof SIZE>
View exactReadonlyType.js
// @flow
export type IProps = {|
+title: string,
+description?: string,
|}
class Post extends React.Component<IProps, {}> {
componentDidMount() {
View flowValuesType.js
// @flow
const SIZE = Object.freeze({
LARGE: "large",
MEDIUM: "medium",
SMALL: "small"
})
type ISize = $Values<typeof SIZE>
View magicFreeze.js
// @flow
const SIZE = /*::Object.freeze(*/{
LARGE: "large",
MEDIUM: "medium",
SMALL: "small"
}
}/*::)*/
type ISize = $Values<typeof SIZE>
View hasFlow.sh
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
View aoc_1.ex
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
View theme-provider-example.tsx
import React from 'react'
import { ThemeProvider } from 'styled-components'
import theme from 'styles/theme'
const App = () => (
<ThemeProvider theme={theme}>
/* your components */
</ThemeProvider>
)
You can’t perform that action at this time.