Skip to content

Instantly share code, notes, and snippets.

import { graphql } from 'gatsby'
export const postFields = graphql`
fragment postFields on PostsJson {
slug
title
content
publishDate(formatString: "MMMM DD, YYYY")
tags
}
// `blog-author.js`
export const query = graphql`
fragment postFields on PostsJson {
slug
title
content
publishDate(formatString: "MMMM DD, YYYY")
tags
}
export const query = graphql`
query ($id: String!) {
post: authorsJson(id: {eq: $id}) {
slug
name
biography
posts {
title
slug
content
export const query = graphql`
fragment postFields on PostsJson {
slug
title
content
publishDate(formatString: "MMMM DD, YYYY")
tags
}
fragment authorFields on AuthorsJson {
export const query = graphql`
query ($id: String!) {
post: postsJson(id: {eq: $id}) {
title
slug
content
publishDate(formatString: "MMMM DD, YYYY")
tags
author {
slug
@matlc
matlc / blog-post.js
Created July 20, 2019 21:40
An example GatsbyJS template for a blog post page
import React from "react"
import { Link } from "gatsby"
import Layout from "../components/layout"
const BlogPost = ({data: {post}}) => (
<Layout>
<h1>{post.title}</h1>
<h4>By <Link to={`/author/${post.author.slug}`}>{post.author.name}</Link></h4>
<p>{post.publishDate}</p>
def start_flow do
streams()
|> Flow.from_enumerables()
|> Flow.filter(&Regex.match?(~r/publishing/, &1))
|> Flow.map(&get_key_and_payload(&1))
|> Flow.partition(key: {:elem, 0})
|> Flow.reduce(fn -> %{} end, fn x, acc ->
Map.put_new(acc, elem(x, 1), elem(x, 2))
end)
end
defmodule Filter do
def start_flow do
streams()
|> Flow.from_enumerables()
|> Flow.filter(&Regex.match?(~r/publishing/, &1))
|> Flow.map(&get_key_and_payload(&1))
|> Flow.partition(key: {:elem, 0})
|> Flow.reduce(fn -> %{} end, fn x, acc ->
Map.put_new(acc, elem(x, 1), elem(x, 2))
end)
@matlc
matlc / simple-sticky-nav.js
Last active February 10, 2016 23:16
A simple sticky-nav implementation
//http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
function isElementInViewport (el) {
//special bonus for those using jQuery
if (typeof jQuery === "function" && el instanceof jQuery) {
el = el[0];
}
var rect = el.getBoundingClientRect();
return (
rect.bottom > 0
);
function logCar(array) {
console.log("I'm a " + array['color'] + " " + array['make']);
}
// Example call for functional version:
logCar({ color: 'blue', make: 'BMW' });