Skip to content

Instantly share code, notes, and snippets.

View seivan's full-sized avatar

Seivan seivan

  • 21:14 (UTC +01:00)
View GitHub Profile
@seivan
seivan / meta-tags.md
Created May 29, 2020 13:42 — forked from kevinSuttle/meta-tags.md
List of Usable HTML Meta and Link Tags
@seivan
seivan / .bashrc
Created May 27, 2020 11:36 — forked from zaps166/.bashrc
Display Git commit hash and branch name and enable git completions
getGitInfo()
{
checksum=$(git rev-parse --short HEAD 2> /dev/null)
branch=$(git symbolic-ref --short HEAD 2> /dev/null)
if [ ! -z $branch ] && [ ! -z $checksum ]; then
echo -e " ($branch $checksum)"
elif [ ! -z $checksum ]; then
echo -e " ($checksum)"
elif [ ! -z $branch ]; then
echo -e " ($branch)"
@seivan
seivan / agents.tsx
Created May 27, 2020 07:04
Browser Agents samples
import { findMatchingBrowser, parseAgent } from "./browser_agent_parser/src";
const Safari_iOS_13_a =
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.63 Mobile/15E148 Safari/604.1";
const Safari_iOS_13_b =
"Mozilla/5.0 (iPad; CPU OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.63 Mobile/15E148 Safari/604.1";
const Safari_iOS_13_c =
"Mozilla/5.0 (iPod; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.63 Mobile/15E148 Safari/604.1";
const Safari_iOS_13_d =
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1";
@seivan
seivan / agents.tsx
Created May 27, 2020 07:04
Browser Agents samples
import { findMatchingBrowser, parseAgent } from "./browser_agent_parser/src";
const Safari_iOS_13_a =
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.63 Mobile/15E148 Safari/604.1";
const Safari_iOS_13_b =
"Mozilla/5.0 (iPad; CPU OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.63 Mobile/15E148 Safari/604.1";
const Safari_iOS_13_c =
"Mozilla/5.0 (iPod; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/83.0.4103.63 Mobile/15E148 Safari/604.1";
const Safari_iOS_13_d =
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1";
@seivan
seivan / _readme.md
Created April 30, 2020 07:42 — forked from andywer/_readme.md
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

@seivan
seivan / DeepReadOnly.ts
Last active April 25, 2020 22:14
Deep Read Only Typescript 3.8
export type DeepReadOnly<P> =
P extends undefined | null | boolean | string | number | Function
? P :
P extends Array<infer T>
? ReadonlyArray<DeepReadOnly<T>> :
P extends Map<infer K, infer V>
? ReadonlyMap<DeepReadOnly<K>, DeepReadOnly<V>> :
P extends Set<infer M>
? ReadonlySet<DeepReadOnly<M>> :
{ readonly [K in keyof P]: DeepReadOnly<P[K]> }
@seivan
seivan / foo.tsx
Created April 16, 2020 07:26 — forked from OliverJAsh/foo.tsx
TypeScript React HOC using `forwardRef`
import * as React from 'react';
import { Component, ComponentClass, createRef, forwardRef, Ref } from 'react';
const myHoc = <ComposedComponentProps extends {}>(
ComposedComponent: ComponentClass<ComposedComponentProps>,
) => {
type ComposedComponentInstance = InstanceType<typeof ComposedComponent>;
type WrapperComponentProps = ComposedComponentProps & {
wrapperComponentProp: number;
@seivan
seivan / app.tsx
Created April 12, 2020 08:02
mobx-react-hook
const WithJustAutoRun = React.memo((props: {
first: Todo;
second: Todo;
counter: number;
}) => {
const rendered = useObservation(() => {
return (
<div>
<h1>
@seivan
seivan / index.js
Last active April 3, 2020 20:58
Homemade observable
import React, { Component } from "react";
import ReactDOM from "react-dom";
import { store, observer } from "./konteks";
import "./index.css";
const state = store({
text: "",
number: 0,
increment: () => state.number++,
@seivan
seivan / dense.rs
Created July 30, 2019 12:52
Dense and Sparse vector for faster O(1) lookup, insert and removal (no order)
#[derive(Debug)]
pub struct DenseVecStorage<T>
where
T: Component,
{
components: Vec<T>,
entity_ids: Vec<usize>,
component_ids: Vec<usize>,
}