Blogs

View as a Table

Install and Use MiniTest


Mini Test

There are two main testing gems within rails, Rspec and Minitest. Since Minitest ships with Rails, lets focus on how to use it with rails.

Installing Minitest

If we are starting from scratch, we can create a new app by rails new TestSuite -T. The -T tells rails not to include any test units upon creating the app. This means that rails will not generate and test or spec files upon generating any scaffolds or models.

We can add minitest to our project by opening ...


Read Blog Post


Install MySQL on Ubuntu 14.04


Getting Started

Let's check our hostname

hostname
hostname -f

The first command shows short hostname, and the second shows your fully qualified domain name (FQDN).

Next, let's make sure we have the most current packages.

sudo apt-get update
sudo apt-get upgrade

Installing MySQL

sudo apt-get install mysql-server mysql-client libmysqlclient-dev

Make sure to chose a secure MySQL root user password when prompted. MySQL...


Read Blog Post


Create Users and Grant Permissions in MySQL


Creating a New User

Lets open the MySQL shell and create a new user.

mysql -u root -p
CREATE USER 'jimmy'@'localhost' IDENTIFIED BY 'password123';

When we first create a user, it will have no permissions, which means it can even login to the MySQL shell, so we need to give it the needed permissions.

GRANT ALL PRIVILEGES ON * . * TO 'jimmy'@'localhost';

The first asterisk in this command refers to the database, in this case we are givin...


Read Blog Post


Vim Cheat Sheet


Some of these commands and shortcuts are based off my own .vimrc file, so it may not work for your setup when you try performing some of the below commands.

MacVim/Gvim

  • :Gblame
  • :Ag count app/controllers
  • :%s/word/love/gc
  • :Ag #navigation-wrapper app/assets/stylesheets
  • Nerd Tree - space + n
  • Fuzzy Search - space + t

Macros

  • q w (then do the commands you'd like repeated)
  • hit q again to stop recording
  • @w (to initiate most recent macro)
  • ...

Read Blog Post


NGINX SSL Lets Encrypt & Auto Renew Setup


Updated for Ubuntu 18.04 / 16.04

SSH into the server

SSH into the server running your HTTP website as a user with sudo privileges.

Add Certbot PPA

You'll need to add the Certbot PPA to your list of repositories. To do so, run the following commands on the command line on the machine:

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update

...


Read Blog Post


Older setup for NGINX SSL Lets Encrypt & Auto Renew Setup


Installation and Setup

sudo su - root # This has to be run as root.
cd /usr/sbin
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
./certbot-auto

Nginx Configuration

Add the following to your nginx server configuration block vim sites-enabled/yourdomain.com

  location ^~ /.well-known/ {
    root /usr/share/nginx/html;
  }

Add folder for well known mkdir -p /usr/share/nginx/html

LetsEncrypt Configuration

Create `mkdir -p /etc/...


Read Blog Post


Install Materialize Gem


Materialize sass ruby gem

materialize-sass is a Sass powered version of Materialize, a modern responsive front-end framework based on Material Design.

example: http://materialize.labs.my/

source: https://github.com/mkhairi/materialize-rails

Dependencies

Rails 5.1+ The Rails JavaScript helpers has been rewritten in a new gem called rails-ujs and they use vanilla JavaScript, so jQuery is not a dependency of Rails anymore. Since materialize...


Read Blog Post


Configure Angular 4


Install Npm and NodeJS

  • see install_type_script.md

Create these files

// package.json

{
  "name": "freelance-camp-fe",
  "version": "1.0.0",
  "scripts": {
    "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
    "lite": "lite-server",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  },
  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/angular/angular.io/blob/master/LICENSE"
    }
  ],
  "dependencies": {
    "@an...

Read Blog Post


Create a Rails API App


Command line for creating new app

Let's first create our API app. The --api makes our app only have the essential code and cuts out any unneeded code an API wouldn't need. The -T tells it not to install any test suite. The -d specifies which database should be used.

rails new app_name --api -T -d postgresql

Create the database.

rails db:create

Use a scaffold.

rails g scaffold NAME title:string description:string file_url:text image_...

Read Blog Post


Install TypeScript


HomeBrew

  • /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • https://brew.sh/

Node.js

  • brew install node
  • node -v

NPM

TypeScript

/usr/local/bin/tsc -> /usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/bin/tsserve...

Read Blog Post