Skip to content

Instantly share code, notes, and snippets.

View dillonhafer's full-sized avatar
🍄
Nintendo Power

Dillon Hafer dillonhafer

🍄
Nintendo Power
View GitHub Profile
@dillonhafer
dillonhafer / ▶️ etc ▶️ newsyslog.d ▶️ rails.conf
Last active March 29, 2021 15:58
Keep rails log files trimmed to 2MB
# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num]
/Users/<username>/dev/<rails projects>/*/log/*.log <username>:staff 644 0 2000 * G
# Mono repos
/Users/<username>/dev/<rails projects>/*/*/log/*.log <username>:staff 644 0 2000 * G
# Deeper mono repos
/Users/<username>/dev/<rails projects>/*/*/*/log/*.log <username>:staff 644 0 2000 * G
function freethousand() {
port="${1:-3000}"
death_level="${2:-SIGINT}"
programs=$(lsof -i tcp:$port | grep "[0-9]" | awk '{print $2" "$1 }' | uniq)
if [ -z "$programs" ]; then
echo "No processes running on port $port"
return
fi
TMPFILE=$(mktemp)
class AuthenticatedController < ApplicationController
include ActionController::HttpAuthentication::Token::ControllerMethods
before_action :authenticate_user
private
def authenticate_user
head(:unauthorized) if current_user.blank?
end
@dillonhafer
dillonhafer / deferred_constraints_2.sql
Last active August 23, 2019 16:22
The only thing I can think of is that the insert statement inside of the CTE is forcing all the connection constraints to deferred, but there’s no documentation that’s even remotely close to that explanation.
create table users (
name text primary key
);
create table groups (
name text primary key,
user_name text not null references users
);
alter table users
@dillonhafer
dillonhafer / deferred_constraints.sql
Created August 23, 2019 16:01
I cannot explain why this works
create table users (
name text not null primary key
);
create table groups (
name text not null primary key,
owner text not null references users
);
create table groups_users (
@dillonhafer
dillonhafer / app.js
Created August 6, 2019 19:13
How to use useCallback with memoized functions
// Taken from https://codesandbox.io/s/usecallback-hooks-vs-class-i1efp
import React, { useRef, useCallback, useState } from 'react'
import ReactDOM from 'react-dom'
import faker from 'faker'
import equal from 'fast-deep-equal'
import times from 'lodash/times'
import './styles.css'
const initialState = times(200, i => ({
id: i,
[Unit]
Description=Budgetal
ConditionPathExists=/home/deploy/budgetal-beta/budgetal
After=network.target
[Service]
EnvironmentFile=/home/deploy/budgetal-beta/budgetal-env
Type=simple
User=deploy
Group=deploy
# APEX & NON-TLS
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 80;
@dillonhafer
dillonhafer / brake-change.md
Last active October 14, 2018 17:02
List of tools needed to change brakes
  • 12mm socket
  • 15mm socket
  • C-clamp
  • Hanging bracket for caliper
  • pads
  • rotor
  • brake grease
  • brake cleaner
  • hammer
  • dot3 brake fluid
#!/bin/bash
# Get file name
dirname=${PWD##*/}
rcfile="$HOME/.coauthor.$dirname"
# Create co author file
touch $rcfile
cat > $rcfile <<COAUTHOR