Skip to content

Instantly share code, notes, and snippets.

View ArthurTruong5's full-sized avatar
🏠
Working from home

Arthur Truong ArthurTruong5

🏠
Working from home
View GitHub Profile
@timm-oh
timm-oh / application_helper.rb
Last active December 17, 2023 21:04
Rails 5.2.3: Cache Active Storage Blobs and Variants through Cloudfront
# app/helpers/application_helper.rb
module ApplicationHelper
# active_storage_item could be a blob or variant object
def proxy_url(active_storage_item, options = {})
options.merge!(host: ENV['ASSETS_HOST']) if ENV['ASSETS_HOST'].present?
# proxy: 'true' allows you to stil have the original functionality while
# being able to proxy through a CDN. You've got to ensure that your CDN
# forwards this param otherwise active storage will always do the default
# behavior which is a redirect to the service.
@bradtraversy
bradtraversy / django_deploy.md
Last active April 4, 2024 11:28
Django Deployment - Digital Ocean

Django Deployment to Ubuntu 18.04

In this guide I will go through all the steps to create a VPS, secure it and deploy a Django application. This is a summarized document from this digital ocean doc

Any commands with "$" at the beginning run on your local machine and any "#" run when logged into the server

Create A Digital Ocean Droplet

Use this link and get $10 free. Just select the $5 plan unless this a production app.

@bradtraversy
bradtraversy / django_cheat_sheet.md
Last active February 24, 2024 23:35
Django command cheat sheet

Django 2.x Cheat Sheet

Creating a virtual environment

We need to create a virtual env for our app to run in: More Here Run this command in whatever folder you want to create your venv folder

python -m venv ./venv
'use strict';
const pointsToFile = uri => /\/[^/]+\.[^/]+$/.test(uri);
exports.handler = (event, context, callback) => {
// Extract the request from the CloudFront event that is sent to Lambda@Edge
var request = event.Records[0].cf.request;
// Extract the URI from the request
@benzkji
benzkji / index.html
Last active March 25, 2021 16:41
simple invisible recaptcha example, works with multiple forms
<script src='https://www.google.com/recaptcha/api.js?hl=de'></script>
check https://developers.google.com/recaptcha/docs/invisible
<div
id="header_recaptcha"
class="g-recaptcha"
data-sitekey="6LctdiQUAAAAAOTUOX92-PkGJXpZgGUp5hrq4l65"
data-size="invisible"
data-callback="recaptcha_submit"
@Kartones
Kartones / postgres-cheatsheet.md
Last active May 22, 2024 17:32
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@tbeauvais
tbeauvais / add_members_uniqueness_index.rb
Created March 6, 2011 17:21
Rails Group/User relationship using join table - has_many :users, :through => :members
#############################################################################
# Migration file to create index so you don't get duplicate users for a group
#############################################################################
class AddMembersUniquenessIndex < ActiveRecord::Migration
def self.up
add_index :group_members, [:group_id,:user_id], :unique => true
end
def self.down
remove_index :group_members, [:group_id,:user_id]