Skip to content

Instantly share code, notes, and snippets.

@adamjohnson
adamjohnson / reusable-fetch-functions.js
Last active December 21, 2021 18:33
Reusable JavaScript fetch functions for JSON GET requests
/*
Reusable `fetch` functions for JSON GET requests
Examples in ES8 & ES5+ for older browser support
*/
'use strict';
const endpoint = 'https://api.chucknorris.io/jokes/random';
// The reusable ES2017 (ES8) function (GET requests & JSON only):
@adamjohnson
adamjohnson / liquid_comment.sublime-snippet
Last active January 29, 2021 23:45
A collection of Liquid Snippets for CleanSlate CMS + Sublime Text 3.
<snippet>
<!-- Snippet to insert a Liquid comment for CleanSlate. -->
<content><![CDATA[
{% comment %}
${1:}
{% endcomment %}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>lqcomment</tabTrigger>
<description>Liquid Comment</description>
@adamjohnson
adamjohnson / google-apps-script-google-sheets-json-api.js
Created January 6, 2021 23:06
The code to get Google Apps Script to create a JSON API from a Google Spreadsheet (code from video: https://www.youtube.com/watch?v=3OakodfKjrU + comments).
// Script from: https://www.youtube.com/watch?v=3OakodfKjrU
function doGet (request) {
var query = request.parameter.q; // If you want to search for specific data, append ?q=my-string-to-search-for
var parameters = 2; // The number of columns in your spreadsheet.
var sheetname = 'Sheet1'; // TODO: Change this to the name of the sheet you want to target.
var doc = SpreadsheetApp.openById(PropertiesService.getScriptProperties().getProperty('key')); // NOTE: 'key' must be the same up here as it is down below in setup();
var sheet = doc.getSheetByName(sheetname);
var lastrow = sheet.getLastRow();
var rows = []; // The array we're going to push our data to.
@adamjohnson
adamjohnson / dot-join-with-newline-as-argument.js
Created November 30, 2020 21:41
Using the newline character with the .join() method in JavaScript to combine a string.
let myString = [
'<div class="container">',
'<h2>This is inserted via JS:</h2>',
'<p>',
'The .join() method can accept newline as an argument.',
'Much better than +!',
'</p>',
'</div>'
].join('\n'); // <-- 🎉
@adamjohnson
adamjohnson / profile_index.json
Created May 18, 2020 16:44
Use CleanSlateCMS to output JSON for a profile index template.
[<r:children:each limit='{$limit}' labels='{$labels}'>
{
"id": <r:page:id />,
"page_published_at": "<r:date_format format='httpdate' value='{page:published_at}' />",
"page_url": "<r:page:url />",
"page_name": "<r:page:name />",
"page_alternate_name": "<r:page:alternate_name />",
"profile_name": "<r:page:content name='wvu-profile__name' />",
"profile_job_title": "<r:page:content name='wvu-profile__job-title' />",
"profile_email": "<r:escape_xml><r:page:content name='wvu-profile__email' /></r:escape_xml>",
@adamjohnson
adamjohnson / google-calendar.html
Last active August 13, 2021 15:00
Pull events from a public Google Calendar using the Google Calendar API. Based off of: https://stackoverflow.com/a/56496854/908059
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Google Calendar API</title>
</head>
<body>
<h1>Events:</h1>
<div id="js-gcal-event">
<!-- SVG loader By Sam Herbert (@sherb). http://goo.gl/7AJzbL -->
@adamjohnson
adamjohnson / sublime-keyboard-shortcuts.md
Last active May 12, 2020 12:19
Sublime Text keyboard shortcuts I should remember

Sublime Text keyboard shortcuts

These are some Sublime Text keyboard shortcuts that I can't seem to remember. I am writing them down in hopes I will use them and commit them to memory.

  1. Find the matching bracket: CTRL + M. Finds: (), {}, [].
  2. Select entire contents of parentheses, brackets, or braces: CTRL+SHIFT+M.
  3. Jump to specific line number: CTRL + P then :xx eg: :50 to go to line 50.
  4. Copy/Cut & Paste entire lines without highlighting: Same keys, paste inserts line above your cursor.
  5. Add a new line from the middle of some text & place cursor on the new line: CTRL/CMD + ENTER.
@adamjohnson
adamjohnson / no-jquery-native-apis.md
Last active December 2, 2022 18:28
A list of "You might not need jQuery" / helpful native API's & methods.

A well designed vanilla JS resource:

https://codetogo.io/

☝️ Can search via method name or the task you want to accomplish.


A great list of commonly used native JS methods and API's:

@adamjohnson
adamjohnson / rcomment.sublime-snippet
Created September 6, 2018 22:43
Sublime Text snippet to insert a Radius comment for CleanSlate.
<snippet>
<!-- Snippet to insert a radius comment for CleanSlate. -->
<content><![CDATA[
<r:comment>
<!-- ${1: } -->
</r:comment>
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>rcomment</tabTrigger>
<description>Insert an r:comment tag for CleanSlate</description>
@adamjohnson
adamjohnson / bracket.sublime-snippet
Created November 28, 2017 17:02
CSS Bracket Expander Sublime Text Snippet
<snippet>
<!-- Type `bracket` and hit tab to open a bracket with a closing comment. -->
<!-- Type the class for the element you are styling and it is placed at the top and in the comment after the closing bracket -->
<!-- Hit tab a second time to put your cursor into a beautifuly tabbed spot within the bracket -->
<!-- https://webdevstudios.com/2016/08/16/snippets-saved-life-how-sublime-text-3-snippets-changed-everything/ -->
<content><![CDATA[
.${1:example} {
${2:Type a class then hit tab!}
} //.${1:example}
]]></content>