Skip to content

Instantly share code, notes, and snippets.

@hjhart
hjhart / reset_slack
Created August 1, 2014 00:31
Log out user from Slack.app and reopen Slack.app
#!/bin/bash
shut_down_slack() {
RELAUNCH_SLACK=0
local process_pattern='[S]lack.app'
local process_identifier='Slack'
ps -e | grep "$process_pattern" > /dev/null
if [ $? -eq 0 ]; then
@hjhart
hjhart / 0_user.rb
Last active January 18, 2024 18:27
Security Interview Problem
# app/models/user.rb
# username :string, null: false
# email :string, null: false
# password :string, null: false
# admin :boolean, null: false, default: false
class User < ApplicationRecord
# Fields
validates :admin, inclusion: { in: [true, false] }
end
@hjhart
hjhart / Gemfile
Last active March 15, 2023 15:04
Trial Fluentd configuration for parsing HAProxy logs from Syslog
source 'https://rubygems.org'
gem 'fluentd'
gem 'fluent-plugin-td'
gem 'fluent-plugin-elasticsearch'
@hjhart
hjhart / blog.md
Last active August 6, 2021 07:35

Effective Caching for Yarn, Bundler, and Rails Asset Pipeline in CircleCI

Phil Karlton said: "There are two hard problems in computer science: cache invalidation, naming things, and off-by-1 errors."

Well, maybe he didn't say exact that, but it's a decent joke anyway.

In this article I'll talk about the first of those problems, caching. And in doing so effectively, how we reduced our CircleCI build times by 33%. For those of you raising your eyebrows and saying "33% off of what?!", I'll direct your eyeballs to the graph below for some absolute numbers.

[ TODO: Show a bar graph of each job going down by a percentage ]

update_homebrew_formula:
description: Pulls in new homebrew formula and caches them
steps:
- run:
name: Set up Cache Key
command: date '+%Y %m %d' > ~/voom/dependency_checksum
- restore_cache:
keys:
- v3-homebrew-{{ .Branch }}-{{ checksum "~/voom/dependency_checksum" }}
precompile_assets:
description: Precompile Rails Assets
steps:
- run:
name: Set up Cache Key
command: find ~/voom/app/javascript ~/voom/app/assets -type f -exec md5 -q {} \; > ~/voom/dependency_checksum
- restore_cache:
keys:
- v3-assets-{{ arch }}-{{ .Branch }}-{{ checksum "~/voom/dependency_checksum" }}
bundle_install:
description: Bundle Install
steps:
- run:
name: Expire cache key every month
command: date '+%Y %m' > ~/voom/dependency_checksum
- restore_cache:
keys:
- v1-bundle-{{ arch }}-{{ checksum "~/voom/dependency_checksum" }}-{{ checksum "~/voom/Gemfile.lock" }}
bundle_install:
description: Bundle Install
steps:
- restore_cache:
keys:
- bundle-{{ arch }}-{{ checksum "~/voom/Gemfile.lock" }}
- bundle-{{ arch }}-
- run:
name: Install Bundler
yarn_install:
description: Yarn Install
steps:
- restore_cache:
keys:
- v1-yarn-{{ arch }}-{{ checksum "~/voom/yarn.lock" }}
- v1-yarn-{{ arch }}-
- run:
name: "Yarn Install (Note: Bump cache prefix if this step takes over 30 seconds.)"
@hjhart
hjhart / query.sql
Last active March 18, 2019 09:51
Identifying Expensive PostgreSQL queries
select substr(query, 0, 250), calls,
to_char(total_time/(60*60), '999,999,9999,999') as "Cumulative Time (hrs)", rows,
to_char(total_time/calls, '999.999') as per_call_ms
from pg_stat_statements
order by total_time desc
limit 12;