Skip to content

Instantly share code, notes, and snippets.

View davidteren's full-sized avatar
👋
Hey, nice to meet you.

David Teren davidteren

👋
Hey, nice to meet you.
View GitHub Profile
@davidteren
davidteren / Rails, Puma & Nginx.md
Last active November 8, 2024 12:13
Example setup for Puma with Nginx in a Rails app

In the apps config/puma.rb file:

Change to match your CPU core count
# Check using this on the server => grep -c processor /proc/cpuinfo
workers 4

# Min and Max threads per worker
threads 1, 6

app_dir = File.expand_path('../..', FILE)

@davidteren
davidteren / index.html.erb
Last active March 22, 2021 08:25
For Article on Medium medium.com/p/46f24daf1b26
<div>
<nav x-data="{ open: false }" @keydown.window.escape="open = false" class="bg-gray-800">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex items-center justify-between h-16">
<div class="flex items-center">
<div class="flex-shrink-0">
<h3 class="text-gray-300 text-lg ">MyApp</h3>
</div>
<div class="hidden md:block">
<div class="ml-10 flex items-baseline">
@davidteren
davidteren / ci.yml
Created May 18, 2020 16:34
GitHub Workflow - Linter & Test CI
name: CI
on: [push, pull_request]
jobs:
linters:
name: Linters
runs-on: ubuntu-latest
steps:
- name: Checkout code
@davidteren
davidteren / nerd_fonts.md
Last active November 13, 2024 19:26
Install Nerd Fonts via Homebrew [updated & fixed]
@davidteren
davidteren / ruby_phonelib_validation_example_za.rb
Last active March 22, 2021 07:24
Example for using the phonelib gem.
# Using the 'phonelib' gem as it's based on Googles libphonenumber library.
# https://github.com/daddyz/phonelib
require 'phonelib'
require 'active_support'
# Set South Africa as the default country
Phonelib.default_country = "ZA"
Phonelib.extension_separate_symbols = ["x", ";"]
@davidteren
davidteren / simple_spy.rb
Created March 22, 2021 10:38
Dev util to show the filename (path), line number, object type and value in the Rails console.
# = SimpleSpy
# Dev util to show the filename (path), line number, object type
# and value in the Rails console.
# === Examples:
# spy val = Object.new
#
# "----------------------------------------------------------------------
# properties.rb:13:in `<main>'+
@davidteren
davidteren / respawn
Last active July 13, 2023 00:57
Script to update dependencies and reset the db.
#!/usr/bin/env ruby
require "fileutils"
# path to your application root.
APP_ROOT = File.expand_path("..", __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
@davidteren
davidteren / active_support_tips_01.rb
Created June 7, 2022 18:19
A good way to validate whether an object is Truthy or Falsey in Ruby or Rails apps is to use the ActiveSupport present? & blank? methods.
# The Rails ActiveSupport core extensions provide additional
# functionality to any Rails or Ruby application.
require "active_support"
# ActiveSupport#blank?
nil.blank? # => true
false.blank? # => true
{}.blank? # => true
[].blank? # => true
"".blank? # => true
@davidteren
davidteren / ruby_on_m1_mac.md
Created August 31, 2022 07:39
Run Ruby via asdf on M1 Macs

Remove Rbenv

brew remove rbenv
rm -rf ~/.rbenv

Remove the following line from your .zshrc

@davidteren
davidteren / rails_7_devise.rb
Created October 31, 2022 17:42
A simple solution for Rails 7 (Hotwire) & Devise sessions destroy
# In config/route.rb
Rails.application.routes.draw do
# other routes...
# Allows us to use link_to for session destroy
devise_scope :user do
get "/users/sign_out", as: "sign_out", to: "devise/sessions#destroy"
end
end