Skip to content

Instantly share code, notes, and snippets.

@ujackson
ujackson / setting-up-heroku-and-cloudflare.md
Created October 13, 2023 17:52 — forked from mrispoli24/setting-up-heroku-and-cloudflare.md
Setting up Heroku and Cloudflare (the right way)

Setting up Heroku and Cloudflare (the right way)

The following outlines how to setup Heroku + Cloudflare with a full SSL certificate. What this means is that communication between the browser and the Cloudflare CDN is encrypted as well as communication between Cloudflare and Heroku’s origin server. Follow these steps exactly and the setup is a breeze.

Step 1: Set up domain names in Heroku

First you want to add the root domain and the www domain to heroku. You do this by clicking into your production application, then going to settings and then scrolling down to Domains and certificates.

Here you will add <your_domain>.com and www.<your_domain>.com. This will give you two CNAME records. They will look something like <your_domain>.com.herokudns.com and www.<your_domain>.com.herokudns.com.

Step 2: Add CNAME records to Cloudfare.

@ujackson
ujackson / STI.md
Created January 12, 2023 12:24 — forked from oojikoo-gist/STI.md
rails: STI(Single Table Inheritance)

Single Table inheritance

reference: blog.thirst.co

In a nutshell, STI allows you to create subclasses of a particular database table. Using a single table, you can cast rows to specific objects that extend the base model.

how to create STI relationships in Rails

Lets say we have a model Computer

@ujackson
ujackson / list_all_rails_models.rb
Created January 12, 2023 11:04 — forked from equivalent/list_all_rails_models.rb
how to get model names of all rails models (works for STI)
#Since Rails doesn't load classes unless it needs them, you must read the models from the folder. Here is the code
Dir[Rails.root.to_s + '/app/models/**/*.rb'].each do |file|
begin
require file
rescue
end
end
models = ActiveRecord::Base.subclasses.collect { |type| type.name }.sort
@ujackson
ujackson / find_unused_images.rake
Created October 21, 2022 22:18 — forked from rafaelp/find_unused_images.rake
Rake task to find unused images on Rails project to deletion.
# It requires ACK - http://betterthangrep.com/
task :find_unused_images do
images = Dir.glob('app/assets/images/**/*')
images_to_delete = []
images.each do |image|
unless File.directory?(image)
# print "\nChecking #{image}..."
print "."
result = `ack -1 -G '(app|public)' --ruby --html --css --js #{File.basename(image)}`
@ujackson
ujackson / 00.md
Created June 8, 2022 19:10 — forked from maxivak/00.md
ActiveAdmin custom action

ActiveAdmin custom action

@ujackson
ujackson / install.sh
Created September 10, 2020 09:51
Installs LAMP with PHP 5.6 on Ubuntu 16.04
#!/bin/bash
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y apache2
sudo ufw allow in "Apache Full"
sudo apt-get install -y mysql-server
# After running this command, select (Y), option 2, then (Y) for the rest of the prompts.
sudo mysql_secure_installation
@ujackson
ujackson / GeneralModal.vue
Created July 24, 2020 14:25 — forked from blackfyre/GeneralModal.vue
Modals in Laravel Nova Tools
<template>
<modal @modal-close="handleClose">
<form
@submit.prevent="handleConfirm"
slot-scope="props"
class="bg-white rounded-lg shadow-lg overflow-hidden"
style="width: 460px"
>
<slot :uppercaseMode="uppercaseMode" :mode="mode">
<div class="p-8">
@ujackson
ujackson / PaginationController.php
Created April 12, 2020 15:37 — forked from Repox/PaginationController.php
Laravel 5 Pagination with transform
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class PaginationController extends Controller
{
@ujackson
ujackson / timezones.php
Created March 11, 2020 19:16 — forked from kulbakin/timezones.php
Array of timezones where keys are PHP timezone names and values are human friendly timezone titles.
<?php
/**
* List of timezones
*/
return array(
'Pacific/Midway' => '(UTC-11:00) Midway',
'Pacific/Niue' => '(UTC-11:00) Niue',
'Pacific/Pago_Pago' => '(UTC-11:00) Pago Pago',
'America/Adak' => '(UTC-10:00) Adak',
'Pacific/Honolulu' => '(UTC-10:00) Honolulu',
@ujackson
ujackson / timezones_array.php
Created March 11, 2020 19:14 — forked from pavellauko/LICENSE
Time zones as arrays (PHP)
<?php
$timezones = array(
'America/Adak' => '(GMT-10:00) America/Adak (Hawaii-Aleutian Standard Time)',
'America/Atka' => '(GMT-10:00) America/Atka (Hawaii-Aleutian Standard Time)',
'America/Anchorage' => '(GMT-9:00) America/Anchorage (Alaska Standard Time)',
'America/Juneau' => '(GMT-9:00) America/Juneau (Alaska Standard Time)',
'America/Nome' => '(GMT-9:00) America/Nome (Alaska Standard Time)',
'America/Yakutat' => '(GMT-9:00) America/Yakutat (Alaska Standard Time)',
'America/Dawson' => '(GMT-8:00) America/Dawson (Pacific Standard Time)',