Skip to content

Instantly share code, notes, and snippets.

View johndhancock's full-sized avatar

John Hancock johndhancock

  • The Boston Globe
  • Dallas, Texas
View GitHub Profile
@johndhancock
johndhancock / select.css
Created April 19, 2023 16:40
Styled select element
select {
display: inline-block;
font-weight: 400;
padding: .5rem 1.5rem .5rem .5rem;
border: 1px solid rgb(175,175,175);
box-shadow: 0 1px 0 1px rgba(0,0,0,.04);
border-radius: .5em;
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
@johndhancock
johndhancock / r-tips-tricks.md
Last active April 13, 2023 14:35
A collection of handy tips and tricks for R

ggplot

Tip Sheet

Color palettes

Saving custom color palettes to a variable, then using them in a ggplot chart

saving the palette

palette <- c(‘#d2848c”, “#fa807s”, “#ee9a00”, “#e0ffff”)

@johndhancock
johndhancock / boston-neighborhoods.json
Last active September 10, 2021 18:54
Boston Neighborhoods.json
[
{
"name": "Roslindale",
"latlong": [-71.1245, 42.2913]
},
{
"name": "Jamaica Plain",
"latlong": [-71.1202, 42.3098]
},
{
// from purpleair.com
// original source: https://docs.google.com/document/d/15ijz94dXJ-YAZLi9iZ_RaBwrZ4KtYeCy08goGBwnbCU/edit#
function aqiFromPM(pm) {
if (isNaN(pm)) return "-";
if (pm == undefined) return "-";
if (pm < 0) return pm;
if (pm > 1000) return "-";
/*
@johndhancock
johndhancock / creditless-footer.hbs
Last active August 18, 2021 18:18
bg-hbs-components
@johndhancock
johndhancock / populateSelectors.js
Last active January 5, 2021 23:12
Populating an empty select element with values dynamically from data
export default function (values) {
// sort value strings alphabetically
values.sort((a, b) => {
if (a.toLowerCase() < b.toLowerCase()) return -1;
if (a.toLowerCase() > b.toLowerCase()) return 1;
return 0;
});
// find select element/elements
const selects = document.querySelectorAll('<<selector name>>');
@johndhancock
johndhancock / circle-ci-debug-steps.md
Last active December 19, 2019 05:10
How to debug Circle-Ci problems, via a real-world example

Early Oct. 2019, I ran into a problem on our Voter Guide where Circle Ci would fail before tests would even run. I could get a basic sense of what was happening via the Circle-Ci interface, but the problem wasn't immediately evident.

After consulting with Andrew Chavez, he pointed me to a page that explains how to SSH into a build running on Circle-Ci to run the commands step-by-step in an attempt to debug the problem.

After SSH-ing in, and cd-ing into the directory on the running build (in this case, cd voter-guide), you're able to run the commands listed in the circle-ci/config.yaml file in the project and seeing the read-out within the terminal as you go along.

In this instance, part of the setup process of the circle ci box involves running this command, which pulls a setup file for Nodejs v 8.x and installs it:

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

  • Create election in elections admin
  • Enter race meta data
  • Set up clarity scrapers for local county races
  • Set up any Collin County race results to be clerked, including clerks
  • Pair race meta data with race aliases from scrapers
  • Pair candidates
  • Create a new homepage in the django admin
  • Set up the featured races for the homepage module
  • !!! Need Allan to remind me how to preview the homepage modules and get the embed codes
  • Create a new liveblog in the datalab/admin
value label
920 A.C. Green
1920 A.J. Bramlett
2062 A.J. Guyton
1627773 AJ Hammons
201985 AJ Price
201166 Aaron Brooks
203932 Aaron Gordon
201189 Aaron Gray
1626151 Aaron Harrison
@johndhancock
johndhancock / loop.html
Last active December 21, 2018 19:56
sample handlebar loop and helper function
<!-- this small piece of html would be inside a larger template that's being used to draw something, such as a post -->
<ul>
{{#each pills}} <!-- your each function called on an array that's part of your data object -->
<li>{{getPillText this}}</li> <!-- passing the value of your array to a helper function (first argument in this template tag -->
{{#/each}}
</ul>