Skip to content

Instantly share code, notes, and snippets.

@jakedohm
jakedohm / getState.twig
Created July 17, 2017 13:22
A twig (Craft CMS templating language) macro to get the full state name from the abbreviated version
{# Macro #}
{% macro getState(abbr) %}
{% set states = {
'AL' : 'Alabama',
'AK' : 'Alaska',
'AZ' : 'Arizona',
'AR' : 'Arkansas',
'CA' : 'California',
'CO' : 'Colorado',
'CT' : 'Connecticut',
const { setContext } = require('apollo-link-context');
const { HttpLink } = require('apollo-link-http');
const { introspectSchema, makeRemoteExecutableSchema } = require('graphql-tools');
const fetch = require('node-fetch');
module.exports = function(api) {
api.createSchema(async function(graphql) {
const http = new HttpLink({
uri: 'http://example.com/api',
fetch
@jakedohm
jakedohm / LoginForm.vue
Last active March 22, 2019 22:57
A Vue component to handle submitting login details with Axios, instead of with a standard HTML form
<template>
<form method="post" accept-charset="UTF-8">
<label for="loginName">Username or email</label>
<input v-model="loginName" id="loginName" type="text" name="loginName" />
<label for="password">Password</label>
<input v-model="password" id="password" type="password" name="password" />
<label>
<input v-model="rememberMe" type="checkbox" name="rememberMe" />
@jakedohm
jakedohm / CreateAccountForm.vue
Created March 27, 2019 15:07
A Vue component to handle submitting account creation details with Axios, instead of with a standard HTML form
<template>
<form method="post" accept-charset="UTF-8">
<h3><label for="username">Username</label></h3>
<input v-model="username" id="username" type="text" name="username" />
<h3><label for="email">Email</label></h3>
<input v-model="email" id="email" type="text" name="email" />
<h3><label for="password">Password</label></h3>
<input v-model="password" id="password" type="password" name="password" />
const { setContext } = require('apollo-link-context')
const { HttpLink } = require('apollo-link-http')
const {
introspectSchema,
makeRemoteExecutableSchema,
} = require('graphql-tools')
const fetch = require('node-fetch')
const http = new HttpLink({
uri: 'http://example.com/api',
<template>
<div v-if="visible" class="modal">
<div>
<div>{{ message }}</div>
<div>
<button class="button-secondary" @click="cancel">Cancel</button>
<button class="button-primary" @click="confirm">Confirm</button>
</div>
</div>
@jakedohm
jakedohm / gridsome.server.js
Last active April 24, 2020 20:42
Gridsome (0.6) + Craft CMS Integration
// Server API makes it possible to hook into various parts of Gridsome
// on server-side and add custom data to the GraphQL data layer.
// Learn more: https://gridsome.org/docs/server-api
// Changes here requires a server restart.
// To restart press CTRL + C in terminal and run `gridsome develop`
const { setContext } = require('apollo-link-context')
const { HttpLink } = require('apollo-link-http')
const {
@jakedohm
jakedohm / Example.vue
Last active May 15, 2019 11:51
Vue Component to Dim Screen
<template>
<!-- Example Usage -->
<div class="menu">
<ScreenDimmer :visible="menuOpen" />
</div>
</template>
<script>
export default {
data() {
@jakedohm
jakedohm / if-to-object.js
Created May 21, 2019 02:11
Showing a refactor of a function with if statements to use key/value pairs in an object
/* Before */
function getErrorMessage(error) {
if(error === 'username') {
return `Username is required`
} else if (error === 'email') {
return `Don't forget your email!`
} else if (error === 'password') {
return `Please enter your password`
}
}
const $ = selector => document.querySelector(selector)
const $$ = selector => document.querySelectorAll(selector)
// $ returns a node (or null)
$('.nav').classList.add('open')
// $$ returns a NodeList (which is empty if no matching elements are found)
$$('ul > li > a').forEach($node => $node.style.background = 'red')