Skip to content

Instantly share code, notes, and snippets.

View drKnoxy's full-sized avatar

Adam Willoughby-Knox drKnoxy

  • Richmond, VA
View GitHub Profile
@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();
/**
@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 / 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 / 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 / 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
func main() {
resp, err := search("hats")
if err != nil {
println("buggered")
} else {
fmt.Printf("%+v\n", resp)
}
}
package main
import (
"io"
"net/http"
"os"
)
const (
apiVersion = "v1"
import (
"encoding/json"
"fmt"
"net/http"
)
// ...
func main() {
url := baseURL + "/search/photos/?query=hats&client_id=" + applicationID
// PhotoResponse is thing
type PhotoResponse struct {
Total int `json:"total"`
TotalPages int `json:"total_pages"`
Results []Photo `json:"results"`
}
// Photo is thing
type Photo struct {
ID string `json:"id"`
Images ImageSet `json:"urls"`
@drKnoxy
drKnoxy / clarify-pingdom.js
Created August 25, 2016 16:41
sort pingdom results, expand poor results
console.clear()
sortPerfTable()
expandPoorSuggestions()
showFullText()
function sortPerfTable() {
const tbl = document.querySelector('.table-perfinsights tbody');