Skip to content

Instantly share code, notes, and snippets.

View jeremylenz's full-sized avatar

Jeremy Lenz jeremylenz

  • New York, NY
View GitHub Profile
@jeremylenz
jeremylenz / prevent_duplicate_vehicle_positions.rb
Created February 23, 2019 22:12
Prevent duplicate record creation by using a hash
def self.prevent_duplicates(objects_to_be_added, existing_vehicle_positions)
# Pass in a list of objects from which VehiclePositions will be created, and compare them to a list of existing VehiclePosition records.
# Return only the objects which would not be duplicates.
# Additionally, if duplicates are found within the existing VehiclePositions, delete them.
start_time = Time.current
logger.info "VehiclePosition prevent_duplicates starting..."
# Coming in, we have an array of hashes and an ActiveRecord::Relation.
# Combine both lists into one array of hashes, with the existing departures first.
@jeremylenz
jeremylenz / MyHorizonalScrollingComponent.js
Last active July 13, 2022 21:41
Use React refs to prevent automatic left scrolling on render
import React from 'react';
import styled from 'styled-components'
import MyHorizonalScrollingComponent from './MyHorizontalScrollingComponent'
const StyledDiv = styled.div`
overflow-x: scroll;
overflow-y: visible;
`
class MyHorizonalScrollingComponent extends React.Component {
@jeremylenz
jeremylenz / JavascriptSetsReducer.js
Last active February 23, 2019 23:36
Use JavaScript Sets in a Redux reducer to keep track of which features are loading
import { SET_LOADER, CLEAR_LOADER } from '../actions/ui'
// Sets are a great way to track API requests for several different kinds of data.
// See my post about this at http://bit.ly/2Taqu5D
const uiState = {
loading: false,
features: new Set(),
}
@jeremylenz
jeremylenz / zapierHelpers.js
Last active November 12, 2019 20:42
Regex helpers to use in Zapier zaps
// match 5 or more digit characters
export const extractRMNum = (taskTitle) => {
const result = taskTitle.match(/\d{5,}/);
if (result) return result[0];
return null;
}
// match https://github.com/{orgName}/{repoNameWithZeroOrOneHyphen}/pull/{1 or more digit chars}
export const extractGithubPrUrl = (taskNotes) => {
const result = taskNotes.match(/https:\/\/github\.com\/\w+\/\w+-*\w*\/pull\/\d+/);
// Zapier task: "Add RM # to Asana task from PR title"
// This is the exact code used in the Zapier step.
const { taskTitle, taskNotes} = inputData;
// match 5 or more digit characters
const extractRMNum = (taskTitle) => {
const result = taskTitle.match(/\d{5,}/);
if (result) return result[0];
return null;
// Zap: Foreman - New RM issue from Asana magic tag
// Step 3: Check Asana tags for RM Tracker type
const { tags, assignee } = inputData;
let tagList = [];
if (tags) tagList = tags.split(",");
const tagNameToRM = {
bug: 1,
feature: 2,
refactor: 4,
#!/usr/bin/env bash
# Get the IP address of a Vagrant box using vagrant ssh-config, then connect to it using sshfs.
cd /home/jeremylenz/code/forklift
VAGRANT_BOX=$1
if [ -z $VAGRANT_BOX ] # if no command-line arg provided, use stable box
then
VAGRANT_BOX="centos7-katello-devel-stable"
fi
echo VAGRANT_BOX: $VAGRANT_BOX
@jeremylenz
jeremylenz / pulp-restart.sh
Last active January 28, 2020 22:52 — forked from aweiteka/pulp-restart.sh
Restart pulp 2 services including MongoDB
#!/usr/bin/env bash
sudo service rh-mongodb34-mongod restart
sudo service pulp_workers restart
sudo service pulp_celerybeat restart
sudo service pulp_resource_manager restart
@jeremylenz
jeremylenz / restart_candlepin.sh
Created January 28, 2020 22:56
Restart Candlepin
#!/usr/bin/env bash
sudo service tomcat restart
@jeremylenz
jeremylenz / virsh-snapshot-commands.sh
Last active January 31, 2020 19:44 — forked from johnpmitsch/blah.sh
vagrant/virsh snapshot commands bashrc
# Add to your ~/.bashrc, then run source ~/.bashrc
# virsh-snapshot-create mybox mysnap
# Run in forklift directory
function virsh-snapshot-create {
vagrant halt $1
virsh snapshot-create-as forklift_$1 $2
vagrant up $1
}