Skip to content

Instantly share code, notes, and snippets.

View narath's full-sized avatar

Narath Carlile narath

View GitHub Profile
# quickly commit your obsidian wiki to git
cd ~/Google\ Drive/wiki
git add .
git commit -m "Update"
exit
@narath
narath / application.js
Last active February 16, 2021 20:41 — forked from bkeepers/application.js
Get timezone offset from the browser and use it for timezones in Rails
// jquery-cookies retired, moved this to js-cookie which no longer requires jQuery
import Cookies from 'js-cookie'
Cookies.set('tz', (new Date()).getTimezoneOffset());
@narath
narath / readme.md
Created July 8, 2021 10:35
Deploying Sidekiq to Ubuntu as a systemctl service using capistrano-sidekiq

I struggled to deploy sidekiq to an Ubuntu 20.04 server using the capistrano-sidekiq gem. Here are the steps I took to get it to work

Add to your Gemfile

gem 'sidekiq', '~> 6.2'

Add to the development group of your gemfile

@narath
narath / migration.rb
Created September 27, 2021 20:11
Rails Migration to add a default value to created_at and updated_at so COPY_FROM can work
class ChangeRawDiagnosesCreatedAtAndUpdatedAt < ActiveRecord::Migration[5.1]
def change
change_column_default :raw_diagnoses, :created_at, from: nil, to: -> { 'CURRENT_TIMESTAMP' }
change_column_default :raw_diagnoses, :updated_at, from: nil, to: -> { 'CURRENT_TIMESTAMP' }
end
end
@narath
narath / README.md
Created September 29, 2022 12:24
Mac Utility: Prevent Citrix Workspace from launching at startup

I only use Citrix occasionally on my Mac. I did not like having it launch at startup. Here's how I stop it from starting at launch time. Derived from this helpful forum post

cd /Library/LaunchAgents
sudo rm com.citrix.*
cd /Library/LaunchDaemons
sudo rm com.citrix.ctx*
@narath
narath / README.md
Created October 4, 2022 13:24
Github action to deploy Jekyll + Tailwindcss with rsync

Read more about getting this working here.

@narath
narath / change_localhost_domain.rb
Created January 5, 2023 13:27
Regular expression for changing the localhost domain
# in general you should never need to use this in Rails
# since you should use the url helpers
# this is a really helpful post about how to do this elegantly with a concern
# https://andycroll.com/ruby/url-helpers-outside-views-controllers/
def change_localhost_domain(url, new_domain)
url.gsub(/http:\/\/localhost:3000|http:\/\/127.0.0.1:3000/, new_domain)
end
@narath
narath / find_all_classes_in_a_directory.rb
Created January 9, 2023 15:43
Find all classes in a directory
# in order to support convention over configuration it can be useful to be able to find all the classes in a directory or
# subdirectory. This lets you have easy factories for subclasses in Rails.
# Requires that you are using Zeitwerk naming conventions for files and classes
class YourRootClass
# this does not work with rails because although the paths are autoloaded
# the objects are not in memory (and are only in memory when instantiated)
# and self.inherited is only called when the classes are put in memory
# note: this likely happens in production but not in development
# def self.inherited(klass)
@narath
narath / app_javascript_controllers_easysubmit.js
Created March 30, 2023 15:20
Stimulus JS TextArea Easy Submit with Cmd or Ctrl Enter
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
submit() {
event.currentTarget.form.requestSubmit()
}
}
@narath
narath / how_to_use_annotations_plugin_with_rails_7.md
Last active February 2, 2024 02:14
How to use the annotations plugin with Rails 7 using Webpacker and Chartkick
yarn add chartjs-plugin-annotation

Then edit app/javascript/application.js

import "chartkick/chart.js"

# Add these lines