Skip to content

Instantly share code, notes, and snippets.

@hugo
hugo / atom.sh
Last active August 29, 2015 13:56
// opens either the file/path passed in as the first argument, or the current directory in Atom
atom() {
path=${1-"$(pwd)"}
echo "opening $path in Atom..."
open -a /Applications/Atom.app "$path"
}
console.log('loaded');
alert('oh noes');
# 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
}
li.moments {
display: none !important;
}
@hugo
hugo / app.js
Last active December 26, 2015 05:29
Mounted app
var express = require('express');
var app = express();
var subapp = require('subapp');
// forwards routes starting with subapp to the subapp, stripping the prefix
app.use('/subapp', subapp);
package main
import (
"fmt"
"net/http"
"time"
)
func viewHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Date", fmt.Sprintf("%s", time.UTC()))
@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"
@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}`
}
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 / 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 });
}
}