Skip to content

Instantly share code, notes, and snippets.

@hugo
hugo / withURQL.tsx
Created December 13, 2019 12:29
Wrap the Next `App` component in a `Provider` from `urql`
import {Provider, Client, createClient} from 'urql'
import NextApp, {AppContext} from 'next/app'
const isServer = typeof window === 'undefined'
type Props = {
client: Client
}
const withURQL = (App: typeof NextApp) =>
@hugo
hugo / saga.js
Created September 14, 2019 21:13
Intermediate sagas
sagaMiddleware.run(rootSaga, someArg)
function* someSaga(someArg, action) {
// ...
}
function* rootSaga(someArg) {
yield takeEvery('SOME_ACTION', someSaga, someArg)
}
@hugo
hugo / saga.js
Created September 14, 2019 21:03
Saga extra arguments
// main.js
const api = new Api({ accessToken: '...', options: {} })
sagaMiddleware.run(rootSaga, api)
// saga.js
function* fetchUser(api, action) {
try {
const user = yield call(api.fetchUser, action.payload.userId);
yield put({ type: "USER_FETCH_SUCCEEDED", user: user });
@hugo
hugo / sagas.js
Created September 14, 2019 21:01
Plain old saga
function* fetchUser(action) {
const api = new Api({ accessToken: '...', options: {} })
try {
const user = yield call(api.fetchUser, action.payload.userId);
yield put({ type: "USER_FETCH_SUCCEEDED", user: user });
} catch (e) {
yield put({ type: "USER_FETCH_FAILED", message: e.message });
}
}
import * as React from 'react';
import {StyleSheet, View, ViewProperties, NativeComponent} from 'react-native';
const top = 'env(safe-area-inset-top)';
const right = 'env(safe-area-inset-right)';
const bottom = 'env(safe-area-inset-bottom)';
const left = 'env(safe-area-inset-left)';
const styles = StyleSheet.create({
all: {
@hugo
hugo / addFileToFolder.js
Created January 23, 2018 15:25
Add a Google Doc to a Google Drive folder
function addFileToFolder(accessToken, fileId, folderId) {
const ps = new URLSearchParams({
addParents: folderId
});
fetch(`https://www.googleapis.com/drive/v3/files/${fileId}?${ps}`, {
method: "PATCH",
headers: {
Authorization: `Bearer ${accessToken}`
}
@hugo
hugo / am_i_up.sh
Last active January 17, 2018 11:27
#!/bin/bash
log_file="/var/log/am_i_up.log"
log() {
echo "$(date) $1" >> $log_file
}
if ping -c 1 8.8.8.8 > /dev/null 2>&1; then
log "network up"
li.moments {
display: none !important;
}
# autocompletion for bash from homebrew
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# generate a 3-character password section
_pw_section() {
env LC_CTYPE=C tr -dc "a-zA-Z0-9" < /dev/urandom | head -c 3
}
console.log('loaded');
alert('oh noes');