Skip to content

Instantly share code, notes, and snippets.

@PlanetRoast
PlanetRoast / Bootstrap Navbar with Devise integration - Basic.erb
Last active April 13, 2020 07:30
Bootstrap powered responsive navbar for your Rails project with some Devise related links baked in.
<nav class="navbar navbar-inverse">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<%= link_to 'Project', root_path, :class => 'navbar-brand' %>

PSQL Cheat Sheet

Working with PostgreSQL via the Ubuntu terminal is great but sometimes I need a reminder for some of the commands. Here is a list of the things I do most often in PSQL.

Console

  • Open Postgres console: PSQL
  • Quit: \q

Databases

  • List all: \l

Access rails console through the terminal

heroku run rails console --app APPNAME

Rake your database through the terminal

heroku run rake db:migrate --app APPNAME
# Password Generator
# Class name: Originally I had named my class 'PasswordGenerator' and found this was causing a 'not a class' error. Changing the name of the class to 'GeneratePassword' fixed the problem.
# Boolean checking: When writing the validations for the arguements I wanted to check if that data passed in was a boolean. I was surprised to discover that you can't use: foo.is_a?(Boolean) in the same way that foo.is_a?(Integer) works. Found a neat way around it: !!foo == foo which converts the value to a boolean then checks it against itself.
class GeneratePassword
def initialize(length, uppercase, lowercase, number, special)
@length = length
@uppercase = uppercase
@lowercase = lowercase
@PlanetRoast
PlanetRoast / Rails AffiliateWindow Scaffold
Created September 12, 2017 08:01
For creating a Product model with all the columns needed for Affiliate Window product feeds.
# Rails Affiliate Window Scaffold
# --------------------------------------------------------------------------------------
# Purpose: For creating all the columns needed for Affiliate Window product feeds.
# Usage: Paste everything below into your terminal then rake db:migrate.
# Note: The backslashes allow the Linux terminal to run multi line commands.
rails g scaffold Product \
aw_deep_link:string \
product_name:string \
aw_product_id:bigint \
# Assorted
# ------------------------------------
# Linux alias commands for general use.
alias sites='cd ~/sites/' # opens the sites folder
alias sb='cd ~/sandbox/' # opens the sandbox folder
alias folder='nemo .' # opens the current directory in nemo file browser
alias xt='exit' # closes the terminal
alias sen='sensors' # shows cpu and gpu temps
alias ..='cd ../' # change directory to parent
# FileGrabber
# Designed for downloading, unzipping, saving, and tidying of affiliate window product feeds.
# -------------------------------------------------------------------------------------------
# Usage: @foo = FileGrabber.new(url: "product-feed-url")
# Optional agrs:
# folder_name (sets the name of the folder which contains the downloaded files)
# folder_path (sets where to store the downloaded files)
# trim (how many downloads do you want to keep saved? The rest will be deleted)
class FileGrabber
class JentriesController < ApplicationController
def index
@jentries = Jentry.all
end
def show
@jentry = Jentry.find_by(:jentry_timestamp => params[:id])
end
class Profile < ApplicationRecord
mount_uploader :avatar, AvatarUploader
geocoded_by :postcode
after_validation :geocode
has_many :profile_services
has_many :services, :through => :profile_services
has_many :testimonials
belongs_to :user
class CompetitionEntry < ActiveRecord::Base
belongs_to :competition
belongs_to :user
has_many :team_members
has_many :competition_entry_images
enum status: %i(semi_finals finals)
scope :all_finals, ->{ where(status: statuses.values_at(*%i(semi_finals finals))) }