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 / mongodb-commands.md
Last active October 25, 2024 15:10
Helpful MongoDB commands

Terminal

  • lsof -iTCP -sTCP:LISTEN -n -P: See what is running on which port
  • kill {portnumber}: Stop whatever is running on designated port
  • mongod --dbpath {dir_path}: Specify where mongodb should start up the database
  • mongosh: Enter the mongodb shell

Mongoshell

  • use {db_name}: Create a database by name
  • db.{collection_name}.insertMany({json_array}): Insert multiple records into a database collection
@johndhancock
johndhancock / ai2html2react.py
Created June 20, 2024 18:45 — forked from hjhilden/ai2html2react.py
Prototype command line script to convert ai2html output to valid React
import sys
import os
import re
dir_path = os.path.dirname(os.path.realpath(__file__)) + '/'
static_content_folder = 'static/custom/ai2html-output/'
# script takes two arguments "input" and "output" and optional static content folder arg
# .js extension is added to output
@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