Skip to content

Instantly share code, notes, and snippets.

View renatorib's full-sized avatar

Renato Ribeiro renatorib

View GitHub Profile
@crisu83
crisu83 / pipe.ts
Last active April 3, 2021 16:44
Simple strongly typed pipe function
type OperatorFn<T> = (value: T) => T;
interface PipeFn {
<T>(...fns: OperatorFn<T>[]): (value: T) => T;
}
const pipe: PipeFn = (...fns) => value =>
fns.reduce((val, fn) => fn(val), value);
export default pipe;
@swyxio
swyxio / svelte.md
Last active November 20, 2020 14:45
Svelte micro-RFC: configurable event modifiers

This is a micro RFC because i'm just jotting down an idea that I would love to have for Svelte, but I'm not sure if it belongs as an official RFC yet. the official RFC process offers no room for lightweight proposals so i am writing a gist.

see also Twitter discussion


The Problem

Svelte offers very useful event modifiers like preventDefault and once.

@ClickerMonkey
ClickerMonkey / types.ts
Last active February 6, 2024 07:21
Typescript Helper Types
// when T is any|unknown, Y is returned, otherwise N
type IsAnyUnknown<T, Y, N> = unknown extends T ? Y : N;
// when T is never, Y is returned, otherwise N
type IsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N;
// when T is a tuple, Y is returned, otherwise N
// valid tuples = [string], [string, boolean],
// invalid tuples = [], string[], (string | number)[]
@sibelius
sibelius / useMemoArray.tsx
Created February 10, 2020 12:22
useMemo for arrays
const arrayCompare = (a: string[], b: string[]) => {
if (a.length !== b.length) {
return false;
}
for (const item of a) {
if (b.indexOf(item) === -1) {
return false;
}
}
@danielr18
danielr18 / Responsive.js
Created November 16, 2018 23:06
Semantic's Responsive with styled-jsx
import React from 'react'
import _ from 'lodash'
import PropTypes from 'prop-types'
import css from 'styled-jsx/css'
import { Responsive as SemanticResponsive } from 'semantic-ui-react'
import classNames from 'classnames'
import hoistNonReactStatics from 'hoist-non-react-statics'
class Responsive extends React.Component {
static propTypes = {
@ninoseki
ninoseki / test.ts
Created September 5, 2018 23:08
Send a screenshot (by using puppeteer) to Slack
import request from "request";
import puppeteer from "puppeteer";
const API_URL = "https://slack.com/api/files.upload";
const SLACK_API_TOKEN = process.env.SLACK_API_TOKEN as string;
const CHANNEL = "general";
(async () => {
const url = "http://neverssl.com"
const browser = await puppeteer.launch();
@brudil
brudil / ConditionalWrap.tsx
Last active April 23, 2018 21:26 — forked from kitze/conditionalwrap.js
one-line React component for conditionally wrapping children
interface IProps {
condition: boolean;
wrap(wrapper: (children: any) => any): any;
children: any;
}
export const ConditionalWrap = ({ condition, wrap, children }: IProps) =>
condition ? wrap(children) : children;
@kitze
kitze / conditionalwrap.js
Created October 25, 2017 16:54
one-line React component for conditionally wrapping children
import React from 'react';
const ConditionalWrap = ({condition, wrap, children}) => condition ? wrap(children) : children;
const Header = ({shouldLinkToHome}) => (
<div>
<ConditionalWrap
condition={shouldLinkToHome}
wrap={children => <a href="/">{children}</a>}
>
@maschill92
maschill92 / demos.cfg
Last active December 27, 2022 20:08
A CS:GO config file to make watching demos much easier.
//----------------------------- MISC -------------------------------\\
//------------------------------------------------------------------\\
sv_cheats "1"
sv_showimpacts "0"
sv_showimpacts_time "2.5"
//---------------------------- BINDS -------------------------------\\
//------------------------------------------------------------------\\
bind "SPACE" "demo_togglepause" // pause/play demo
bind "c" "r_cleardecals" // get rid of bulletholes and black residue from grenade explosions
@DmitrySoshnikov
DmitrySoshnikov / Recursive-descent-backtracking.js
Last active January 3, 2024 17:15
Recursive descent parser with simple backtracking
/**
* = Recursive descent parser =
*
* MIT Style License
* By Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*
* In this short lecture we'll cover the basic (non-predictive, backtracking)
* recursive descent parsing algorithm.
*
* Recursive descent is an LL parser: scan from left to right, doing