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 / html
Last active March 22, 2024 19:24
flowbite_template_example.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<title>Document</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.3.0/flowbite.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.3.0/flowbite.min.js"></script>
@davidteren
davidteren / print_struct_members.md
Created August 11, 2023 18:53
A simple way to get all the classes and their members from a struct

Sometimes Structs have a number of class types each with their own members.

response = mediaconvert.create_job(job_params)

# This output exampled has been shortened a lot
# => #<struct Aws::MediaConvert::Types::CreateJobResponse job=#<struct Aws::MediaConvert::Types::Job arn="arn:aws:mediaconvert:us-west-1:<protected>:jobs/<hidden>-nedzn7", ...,  error_message=nil, id="1691778742640-nedzn7", job_template="arn:aws:mediaconvert:us-west-1:<protected>:jobTemplates/Test Job Template - no Audio", output_group_details=nil, queue="arn:aws:mediaconvert:us-west-1:<protected>:queues/Default", caption_selectors=nil, deblock_filter=nil, denoise_filter=nil, file_input="https://some-bucket.s3-eu-west-1.amazonaws.com/some-path/somehash/test%20vid%20copy%208.mp4", filter_enable=nil, filter_strength=nil, input_clippings=nil, program_number=nil, psi_control=nil, timecode_source="ZEROBASED", video_selector=#<struct Aws::MediaConvert::Types::VideoSelector, output_groups=[#<struct Aws::MediaConvert::Types::OutputGroup c
@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
@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 / 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 / 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 / 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 / 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", ";"]