Skip to content

Instantly share code, notes, and snippets.

@trevorrjohn
trevorrjohn / add_to_path.sh
Last active August 14, 2024 21:54
The goal of these function are to automatically add and remove your Rails ./bin/ directory to your and remove it when it doesn't exist. I am sure there are edge cases I missed or maybe there is a better way to do this. :shurg:
# NOTE:
# Make sure you add this function to your zshrc file or link to the file.
# it could look like this line in your `~/.zshrc`
# . PATH_TO_FILE/add_to_path.sh
#!/bin/sh
# Function to add a directory to PATH
#
# Usage:
@trevorrjohn
trevorrjohn / rails-model-generator-with-default-timestamps.md
Last active August 2, 2024 23:21
Set default timestamp when generating new model

Many times I want to always set the timestamps when a model is created. At times you will want to create a model in sql only for it to fail because you forgot to set the created_at and updated_at columns to some value. By setting a sane default you will avoid having to think about this in the future.

In your Rails application, copy the code below and paste it in the following file: lib/templates/active_record/migration/create_table_migration.rb.tt

class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
  def change
    create_table :<%= table_name %><%= primary_key_type %> do |t|
<% attributes.each do |attribute| -%>
@trevorrjohn
trevorrjohn / instructions.md
Last active July 28, 2021 01:46
Encrypt file using private public key

Context: "User A" has a password in a text file that he needs to share with "User B".

  1. User A and User B - Download and install openssl
% brew update && brew install openssl
  1. User B - Generate a public key
@trevorrjohn
trevorrjohn / foo.scss
Last active November 11, 2019 18:31 — forked from theck01/foo.scss
.relationship-list-item a {
text-decoration: none !important;
}
.relationship-list-item:hover {
border-left: 5px solid lighten($secondary-color, 15%);
}
.relationship-list-item:hover .relationship-list-icon {
background: lighten($secondary-color, 15%);
.relationship-list-item:hover {
a {
text-decoration: none !important;
}
.relationship-list-icon {
background: lighten($secondary-color, 15%);
}
&.selected {
border-left: 5px solid darken($secondary-color, 10%);
.relationship-list-icon {
@trevorrjohn
trevorrjohn / graphQL-rails-boolean.rb
Created September 13, 2018 13:32
Convert ActionController::Params to boolean values for GraphQL-ruby
# config/initializers/graphql_boolean_parameter.rb
# frozen_string_literal: true
GraphQL::BOOLEAN_TYPE.class_eval do
REGEX = /^(true|false|t|f|0|1)$/
define_method(:validate_input) do |value, ctx|
super(coerce_input(value, ctx), ctx)
end
@trevorrjohn
trevorrjohn / tmux.conf
Created August 6, 2018 21:32
tmux.conf
# brew install reattach-to-user-namespace
# https://robots.thoughtbot.com/how-to-copy-and-paste-with-tmux-on-mac-os-x
set-option -g default-command "reattach-to-user-namespace -l bash"
# Act like Vim
set-window-option -g mode-keys vi
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R

Keybase proof

I hereby claim:

  • I am trevorrjohn on github.
  • I am trevorrjohn (https://keybase.io/trevorrjohn) on keybase.
  • I have a public key ASCm2yttO3fQsLFF0hWQmJ6aEJRCCWliON8GUYN-Le0uOQo

To claim this, I am signing this object:

PublishSubject<Repo> subject =
PublishSubject.create();
when(service.getRepo(anyString())
.thenReturn(subject.asObservable());
activity.onCreate(null);
subject.onNext(new Repo("Subject!"));
Observable.create(OnSubscribe<T> onSubscribe);
public interface OnSubscribe<T> {
void call(Subscriber<T> subscriber);
}
public abstract class Subscriber<T>
implements Observer<T>, Subscription { /**/ }