Skip to content

Instantly share code, notes, and snippets.

View drKnoxy's full-sized avatar

Adam Willoughby-Knox drKnoxy

  • Richmond, VA
View GitHub Profile
func main() {
resp, err := search("hats")
if err != nil {
println("buggered")
} else {
fmt.Printf("%+v\n", resp)
}
}
@drKnoxy
drKnoxy / HeroImage.jsx
Created March 13, 2017 00:48
Responsive Image
import React from 'react';
import styled from 'styled-components';
/**
* @param {string} src
* @param {string} alt
* @param {number} width Some ratio you like
* (Math.sqrt(5) + 1) / 2 : Golden Ratio
* 16/9 : Widescreen
* 2.414 : Ultra wide
@drKnoxy
drKnoxy / unsplash_grid.jsx
Created March 17, 2017 17:24
Unsplash image grid
function ImageGrid({ images = [], imageSelect = () => {} }) {
function Img({ id = '', urls = {}, onClick = () => {}, style = {} }) {
return (
<a style={style} onClick={e => onClick(urls)}>
<img src={urls.small} alt="" />
</a>
);
}
return (
@drKnoxy
drKnoxy / redux-render-props.js
Created January 4, 2018 17:34
Redux render prop
const withState = connect(state => ({
visitor: getVisitor(state),
form: getRegForm(state),
activeUsers: getActiveUsers(state),
}));
const HomeData = withState((children, ...rest) => children(...rest) );
// in usage
export function Home() {
@drKnoxy
drKnoxy / pure-theme-plus-git-upstream.sh
Created May 8, 2018 19:12
Adding the upstream branch to your zsh pure theme
# Nothing to do if we aren't in a git repo
if git rev-parse --git-dir > /dev/null 2>&1; then
# Get the name of upstream
upstream=$(command git rev-parse --symbolic-full-name --abbrev-ref @{u} 2>/dev/null)
# Check if we have an upstream, and that it is different than our current branch
if [[
$(command git rev-parse --symbolic-full-name --abbrev-ref @{u} 2>/dev/null | sed 's/origin\///')
!= $(command git rev-parse --abbrev-ref HEAD)
&& ! -z "$upstream"
@drKnoxy
drKnoxy / move_collections.js
Last active January 26, 2019 12:17
Moving a document and subcollection in a cloud function
import functions from "firebase-functions";
import admin from "firebase-admin";
// client code
// firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idToken) {
// })
admin.initializeApp();
/**