Skip to content

Instantly share code, notes, and snippets.

Seivan seivan

Block or report user

Report or block seivan

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
FredyC / examples.ts
Last active Apr 28, 2020
Children handling with React FC
View examples.ts
const NoChildrenAllowed: ReactFC<NoChildren> = () => null
const RequireSingleChild: ReactFC<Required<SingleChild>> = () => null
type TProps = Required<SomeChildren> & {
otherProp: number
const RequireMoreChildrenAndOtherProps: ReactFC<TProps> = () => null
andywer /
Last active May 21, 2020
React - Functional error boundaries

React - Functional error boundaries

Thanks to React hooks you have now happily turned all your classes into functional components.

Wait, all your components? Not quite. There is one thing that can still only be implemented using classes: Error boundaries.

There is just no functional equivalent for componentDidCatch and deriveStateFromError yet.

Proposed solution

View gist:38996b3421ff946d6eb00d84fb8ed331
Shibboleths. Add these up and if you have an opinion on five - agreeing *or* disagreeing - we’d love to hear from you. Do these elicit strong feelings? See the note at the bottom.
- You understand discriminated unions, and how to use the type system to enforce exhaustive checks and other useful patterns.
- You can describe good and bad use cases for single page applications.
- You can describe why nullable types and a type system that enforces it are advantageous over type systems like Java’s.
- You can and have extracted declarative implementations out of imperative code. You know when it’s worth it and when it’s not.
use std::path::PathBuf;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::thread;
use std::os::raw::c_void;
use std::rc::Rc;
use std::cell::{Cell, RefCell};
use std::i16;
use std::time::Instant;
use failure::{err_msg, Error};
teamon / box.ex
Created Aug 25, 2017
Define elixir structs with typespec with single line of code
View box.ex
defmodule Box do
defmacro __using__(_env) do
quote do
import Box
@doc """
Define module with struct and typespec, in single line
bsedat / Dockerfile
Last active Apr 5, 2020
Elixir Phoenix Umbrella App + Distillery Multistage Docker Build
View Dockerfile
FROM elixir:1.4.5 as asset-builder-mix-getter
ENV HOME=/opt/app
RUN mix do local.hex --force, local.rebar --force
# Cache elixir deps
COPY config/ $HOME/config/
COPY mix.exs mix.lock $HOME/
COPY apps/myproject_web/mix.exs $HOME/apps/myproject_web/
COPY apps/myproject_web/config/ $HOME/apps/myproject_web/config/
stevedonovan /
Created Apr 14, 2017
An ergonomic way of saying Rc<RefCell>
use std::rc::Rc;
use std::cell::{RefCell,Ref, RefMut};
use std::ops::Deref;
use std::fmt;
struct Shared<T> {
v: Rc<RefCell<T>>
View LazyRoute.tsx
import * as React from "react";
import { observer } from "mobx-react";
import inject from "../store/Inject";
import { addTask } from "../module/task";
import { add, exists, fetch } from "../module/cache"
import { Match, Redirect } from "react-router";
import { default as load } from "../module/load";
import { ApplicationStore } from "../store/ApplicationStore";
import { UserStoreKey, UserStoreStructure } from "../store/UserStore";
kharrison / Country.swift
Last active Sep 24, 2019
Swift Hash Functions
View Country.swift
import Foundation
struct Country {
let name: String
let capital: String
var visited: Bool
extension Country: Equatable {
static func == (lhs: Country, rhs: Country) -> Bool {
mrrooijen / global_register.ex
Created Jan 2, 2017
Ensure that only one instance of a given (supervised) process exists in the cluster.
View global_register.ex
defmodule Party.Clock do
use GenServer
def start_link do
case GenServer.start_link(__MODULE__, [], name: {:global, __MODULE__}) do
{:ok, pid} ->
{:ok, pid}
{:error, {:already_started, pid}} ->
IO.puts("Already started!!")
You can’t perform that action at this time.