Skip to content

Instantly share code, notes, and snippets.

View gustavoguichard's full-sized avatar
🏠
Working from home

Guga Guichard gustavoguichard

🏠
Working from home
View GitHub Profile
@gustavoguichard
gustavoguichard / gist:4087005
Created November 16, 2012 12:38
open iPhone simulator from terminal
alias iPhone="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator"
@gustavoguichard
gustavoguichard / type-utils.ts
Created March 23, 2023 03:23
Type utilities
type Specify<T> = T extends any ? (k: T) => void : never
// Real intersection: UnionToIntersection<`c${string}` | 'car'> will become `c${string}`
type UnionToIntersection<T> = Specify<T> extends (a: infer A) => void ? A : never;
// Transforms 'a' | 'b' into ((f: "a") => void) & ((f: "b") => void)
type UnionToOverloads<U> = UnionToIntersection<Specify<U>>;
// Still figuring out why this happens
// ((f: "a") => void) & ((f: "b") => void) will become "b"
@gustavoguichard
gustavoguichard / union-to-tuple.ts
Last active January 6, 2023 20:09
Union to Tuple
type Specify<T> = T extends any ? (k: T) => void : never
// Real intersection: UnionToIntersection<`c${string}` | 'car'> will become `c${string}`
type UnionToIntersection<T> = Specify<T> extends (a: infer A) => void ? A : never;
// Transforms 'a' | 'b' into ((f: "a") => void) & ((f: "b") => void)
type UnionToOverloads<U> = UnionToIntersection<Specify<U>>;
// Still figuring out why this happens
// ((f: "a") => void) & ((f: "b") => void) will become "b"
@gustavoguichard
gustavoguichard / tailwind.config.js
Created March 22, 2022 12:12
Tailwind children selector
module.exports = {
theme: {
extend: {
// ...
},
},
plugins: [
function ({ addVariant }) {
addVariant('children', '& > *')
},
@gustavoguichard
gustavoguichard / abort.js
Created August 30, 2021 20:28
Abort a promise
const controller = new AbortController()
const toBeAborted = fetch('/', { signal: controller.signal })
controller.abort()
@gustavoguichard
gustavoguichard / body.getReader.js
Created August 30, 2021 20:25
Show body data in pieces
const res = await fetch('/')
const reader = res.body.getReader()
const data = await reader.read()
new TextDecoder().decode(data.value)
while(!data.done) {
console.log(new TextDecoder().decode(data.value))
data = await reader.read()
}
@gustavoguichard
gustavoguichard / useStore.js
Created April 16, 2021 19:40
Global state
import { useState, useEffect } from 'react'
function setState(newState, updateContext) {
this.state = { ...this.state, ...newState }
this.listeners &&
this.listeners.forEach(([context, listener]) => {
updateContext === context && listener(this.state)
})
}
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ →\ \1/'
}
# export PS1="\[\e[0;31m\][\u] \W\n$ "
export PS1='\[\e[1;37m\]\W\[\e[1;36m\]$(parse_git_branch)\[\e[0;39m\]\n$ '
export PROMPT_COMMAND='echo -ne "\033]0;${PWD}\007"'
ruby -F, -ane \
'puts $F[15].gsub(/"/, "") unless $F[15] !~ /\w+@\w+\.\w{2,5}/' \
~/Desktop/cadastros.csv > emails.txt
import compact from 'lodash/compact'
import get from 'lodash/get'
import head from 'lodash/head'
import orderBy from 'lodash/orderBy'
const getFirstValue = (el, path) => {
const paths = path.split('|')
const values = paths.map(path => get(el, path))
return head(compact(values))
}