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 / 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 / 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 / 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 / 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 / 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 / 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 / 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>