Skip to content

Instantly share code, notes, and snippets.

View wdchris's full-sized avatar

Chris Harding wdchris

View GitHub Profile
@wdchris
wdchris / trello-authenticate.html
Last active May 18, 2020 17:29
Authenticate with the Trello API
<script src="https://api.trello.com/1/client.js?key=MY_KEY"></script>
<script type="text/javascript">
Trello.authorize({
name: "My site",
scope: {
read: true,
write: false
},
expiration: "never",
@wdchris
wdchris / trello-boards.js
Last active May 18, 2020 17:29
Load boards from the Trello api
getBoards() {
return new Promise((resolve, reject) => {
Trello.get(
"/members/me/boards/",
boards => resolve(boards),
error => reject(new Error(`Getting boards failed: ${error}`))
);
});
}
@wdchris
wdchris / trello-dashboard-api-calls.js
Last active May 18, 2020 17:29
Function for calling Trello api to load cards
let boards = await trelloData.getBoards();
boards = await Promise.all(
boards.map(async board => {
const lists = await trelloData.getLists(board.id, true);
board.lists = lists;
return board;
})
);
@wdchris
wdchris / trello-dashboard-filter.js
Last active May 18, 2020 17:29
A function to filter Trello lists based on a label
const filterCards = (boards, filter) =>
boards.reduce((result, board) => {
const cardsResult = board.lists.reduce((cards, list) => {
if (
board.closed === false &&
list.closed === false &&
(filter.length === 0 ||
list.name.toLowerCase() === filter.toLowerCase())
) {
return cards.concat(list.cards.filter(card => card.closed === false));
@wdchris
wdchris / netlify-forms.jsx
Last active May 18, 2020 17:28
Sample React markup for Netlify forms
<form
name="register"
data-netlify="true"
data-netlify-honeypot="sneaky-sneaky"
onSubmit={handleSubmit}
>
<input
type="text"
name="email"
placeholder="Enter your email"
<input type="hidden" name="form-name" value="register" />
<input name="sneaky-sneaky" />
const [email, setEmail] = useState("")
const handleSubmit = e => {
fetch("/", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: formEncode({ "form-name": "register", email: email }),
})
.then(() => alert("Success!"))
.catch(error => alert(error))
import React, { useState } from "react"
const formEncode = data => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + "=" + encodeURIComponent(data[key]))
.join("&")
}
const RegistrationForm = () => {
const [email, setEmail] = useState("")
override func viewDidLoad() {
super.viewDidLoad()
contentView.addSubview(collectionView)
collectionView.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 0).isActive = true
collectionView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 0).isActive = true
collectionView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor, constant: 0).isActive = true
collectionView.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor, constant: 0).isActive = true
}
var itemsPerRow: CGFloat = 3
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
guard let flow = collectionViewLayout as? UICollectionViewFlowLayout else {
fatalError("only flow layout is supported")
}
let paddingSpace = flow.sectionInset.left + flow.sectionInset.right + (minimumInteritemSpacing * itemsPerRow)
let availableWidth = collectionView.frame.width - paddingSpace
let widthPerItem = availableWidth / itemsPerRow