Skip to content

Instantly share code, notes, and snippets.

View crisu83's full-sized avatar

Christoffer Niska crisu83

View GitHub Profile
crisu83 / Validator.kt
Last active September 5, 2022 07:22
A validator implementation written in Kotlin.
View Validator.kt
sealed interface Validator {
fun validate(value: String): Int?
object RequiredValidator : Validator {
override fun validate(value: String): Int? =
if (value.isNotBlank()) null else ValidationError.Required
object EmailValidator : Validator {
crisu83 / Example.kt
Last active January 11, 2022 09:12
A predictable state container (like Redux) written in Kotlin for use with Android view models.
View Example.kt
data class CounterUiState(val counter: Int = 0) : State
sealed class CounterAction : Action {
object Increment : CounterAction()
object Decrement : CounterAction()
data class SetValue(val value: Int) : CounterAction()
class CounterViewModel : ViewModel() {
crisu83 / DatePicker.kt
Last active August 17, 2023 17:55
DatePicker and TimePicker components for Jetpack Compose.
View DatePicker.kt
fun DatePicker(
label: String,
value: String,
onValueChange: (String) -> Unit = {},
keyboardActions: KeyboardActions = KeyboardActions.Default,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
pattern: String = "yyyy-MM-dd",
) {
val formatter = DateTimeFormatter.ofPattern(pattern)
crisu83 / settings.json
Last active March 28, 2023 14:08
My VSCode settings
View settings.json
"[rust]": {
"editor.formatOnSave": true
"[typescript]": {
"editor.formatOnSave": true
"[typescriptreact]": {
"editor.formatOnSave": true
crisu83 / GuessANumber.kt
Last active September 5, 2022 07:25
A "guess a number game" implementation written in Kotlin that we wrote together with my 12 year old son when learning basic concepts in programming.
View GuessANumber.kt
import kotlin.random.Random
fun main() {
val secretNumber = Random.nextInt(1, 100)
var numTries = 0
var numTriesLeft: Int
var gameWon = false
println("Welcome to Guess a number!")
crisu83 / LoginScreen.kt
Last active October 5, 2021 09:28
View LoginScreen.kt
fun LoginScreen(
viewModel: LoginViewModel,
navigateToOverview: () -> Unit = {},
onBack: () -> Unit = {},
) {
val uiState by viewModel.uiState.collectAsState()
val (username, setUsername) = viewModel.username
crisu83 / graphql.ts
Created September 4, 2021 09:40
GraphQL API route with remote schema
View graphql.ts
// See:
import {AsyncExecutor} from '@graphql-tools/delegate';
import {introspectSchema, wrapSchema} from '@graphql-tools/wrap';
import {ApolloServer} from 'apollo-server-micro';
import {print} from 'graphql';
import fetch from 'isomorphic-unfetch';
import {NextApiRequest, NextApiResponse} from 'next';
import getConfig from 'next/config';
crisu83 / graphql.ts
Created September 3, 2021 17:57
GraphQL API route
View graphql.ts
import {ApolloServer} from 'apollo-server-micro';
import {NextApiRequest, NextApiResponse} from 'next';
import {resolvers} from '@/graphql/resolvers';
import typeDefs from '@/graphql/schema.graphql';
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
return new ApolloServer(
crisu83 / button.tsx
Last active May 19, 2021 09:02
Design system written in TypeScript and built on top of Style System (and Styled Components).
View button.tsx
// Example button component
import shouldForwardProp from '@styled-system/should-forward-prop';
import {darken, lighten} from 'polished';
import React, {FunctionComponent, forwardRef} from 'react';
import {variant as variantFn} from 'styled-system';
import {
crisu83 / ci.yml
Last active April 8, 2021 08:15
CI workflow for GitHub Actions. Paste the contents in .github/workflows/ci.yml to enable it for your repository.
View ci.yml
name: CI
on: [push]
name: Schema
runs-on: ubuntu-latest
- name: Checkout
uses: actions/checkout@master
- name: Inspect Schema