Skip to content

Instantly share code, notes, and snippets.

View rickyhaswifi's full-sized avatar

Ricardo Bautista rickyhaswifi

View GitHub Profile
@rickyhaswifi
rickyhaswifi / Terminal.textile
Last active November 9, 2020 21:05
Terminal en español - Spanish Cheat Sheet

COMANDOS BÁSICOS

cd Directorio Principal
cd [folder] Cambiar Directorio
ls Lista de todo
ls -a Lista incluyendo archivos ocultos
mkdir [dir] Crear carpeta
mkdir -p [dir]/[dir] Crear carpeta dentro de otra carpeta
sudo [command] Acción con super permiso
open [file] Abre
@rickyhaswifi
rickyhaswifi / netlify.toml
Last active August 10, 2023 00:48
React Router Netlify - Fix for not found page
#https://stackoverflow.com/questions/58065603/netlify-renders-404-on-page-refresh-using-react-and-react-router
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
@rickyhaswifi
rickyhaswifi / Footer.js
Last active May 6, 2020 22:39
Website footer with updating year
@rickyhaswifi
rickyhaswifi / Procfile
Created October 9, 2019 01:07
rails/Procfile - for heroku
web: bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}
@rickyhaswifi
rickyhaswifi / App.js
Last active October 2, 2019 01:51
React Authentication - Devise/Rails
import React from 'react';
import { Switch, Route } from 'react-router-dom';
import { Container } from 'semantic-ui-react';
import Navbar from './components/shared/Navbar';
import Home from './components/shared/Home';
import Nomatch from './components/shared/Nomatch';
import Login from './components/auth/Login';
import Register from './components/auth/Register';
import FetchUser from './components/auth/FetchUser';
@rickyhaswifi
rickyhaswifi / youtube.js
Created September 20, 2019 22:17
Extract ID from user input in JS
const youtubeID = (link) => link.slice(link.lastIndexOf('=')+1);
console.log(youtubeID('https://www.youtube.com/watch?v=N65RvNkZFGE'));
const shortLink = (short) => short.slice(short.lastIndexOf('e/')+2);
console.log(shortLink('https://youtu.be/N65RvNkZFGE'));
@rickyhaswifi
rickyhaswifi / model.rb
Last active December 29, 2022 20:56
Youtube & Spotify Embedded Content for Rails - Place this in model to slice specific strings
#YOUTUBE
def youtube_id
youtube_id = self.modelkey
youtube_id.gsub("https://www.youtube.com/watch?v=", "")
end
#Call as @model.youtube_id
<iframe width="560" height="315" src="https://www.youtube.com/embed/<%= @.youtube_id %>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
#SPOTIFY
@rickyhaswifi
rickyhaswifi / controller_macros.rb
Created September 12, 2019 00:24
Controller testing with Devise
module ControllerMacros
def login_user
before(:each) do
@request.env["devise.mapping"] = Devise.mappings[:user]
@user = User.create(email: 'test@test.com', password: 'password',
first_name: 'Test', last_name: 'Tester', age: 27)
sign_in @user
end
end
end
@rickyhaswifi
rickyhaswifi / rails_helper.rb
Last active September 11, 2019 01:58
Rails Testing rails_helper.rb & spec_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'simplecov'
SimpleCov.start
@rickyhaswifi
rickyhaswifi / controller.rb
Last active August 30, 2019 00:51
The patter for rails controller
# READ - GET
# Page will see and interact with
# shows record from the db onto the pages
# index action - see all of the record for the table
@model_names = Model_name.all
# gets all the records and set them to a variable
# show action - see a single record, id
@model_name = Model_name.find(params[:id])