Skip to content

Instantly share code, notes, and snippets.

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

Hồ Viết Thiên thienhv

🏠
Working from home
View GitHub Profile
@thienhv
thienhv / vue-folder-structure.md
Created January 17, 2024 09:30 — forked from plinionaves/vue-folder-structure.md
Vue Project Folder Structure

Style Guide

This file describes de required Style Guide used by Basicamente to keep the Best Practices on develop new features or improve/change existents one.

Project folder structure

Always follow the folder structure below:

src/
@thienhv
thienhv / secure_rails
Created December 26, 2022 12:48 — forked from mindscratch/secure_rails
Start WEBrick with SSL enabled. ## Usage bundle exec ruby script/secure_rails s -e <environment> -p <port>
#!/usr/bin/env jruby
%W{rails/command/server rack webrick webrick/https}.each { |lib| require lib }
ENV['HTTPS'] = 'on'
module Rails
class Server < ::Rack::Server
def default_options
super.merge({
@thienhv
thienhv / simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Created October 6, 2022 00:16 — forked from iscott/simple_authentication_rails_5_bcrypt_and_has_secure_password.md
Cheat Sheet: Simple Authentication in Rails 5 with has_secure_password

Cheat Sheet: Simple Authentication in Rails 6 with has_secure_password

The goal of this cheatsheet is to make it easy to add hand-rolled authentication to any rails app in a series of layers.

First the simplest/core layers, then optional layers depending on which features/functionality you want.

Specs
AUTHOR Ira Herman
LANGUAGE/STACK Ruby on Rails Version 4, 5, or 6
@thienhv
thienhv / vue.md
Created April 14, 2022 16:17 — forked from DawidMyslak/vue.md
Vue.js and Vuex - best practices for managing your state

Vue.js and Vuex - best practices for managing your state

Modifying state object

Example

If you have to extend an existing object with additional property, always prefer Vue.set() over Object.assign() (or spread operator).

Example below explains implications for different implementations.

@thienhv
thienhv / README.md
Created March 27, 2022 08:35 — forked from jesster2k10/README.md
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

@thienhv
thienhv / slim_vs_haml.md
Created March 14, 2022 02:06 — forked from pboling/slim_vs_haml.md
Slim vs Haml

Analysis of Slim vs. Haml Project Health

  • Static data as of April 13, 2015, some updates as of October 1, 2015
# Metric Haml Slim Winner
1 Issues Open Issues Open Issues Slim
2 Stars Stars Open Issues Slim
3 Quality Stars Code Quality Slim
4 T
@thienhv
thienhv / api_content_type.rb
Created March 8, 2022 15:26 — forked from tstachl/api_content_type.rb
This is a simple Rack Middleware to set the request content type for specific routes. It checks if a content type is set and does not override the existing one. The options allow you to specify the request methods, path (with a string or a regular expression) and the content type to be set.
module Rack
class ApiContentType
def initialize(app, methods = [:post, :patch], path = /^\/api\/v2+/, content_type = 'application/json')
@app = app
@methods = (methods.is_a?(Array) ? methods : [methods]).map{ |item| item.to_s.upcase }
@path = path
@content_type = content_type
end
def call(env)
@thienhv
thienhv / capybara.rb
Created January 1, 2022 07:28 — forked from papitodev/capybara.rb
Capybara Remove Chrome Warning
Capybara.register_driver :chrome_custom do |app|
caps = Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => {
"args" => ["--headless", "--disable-site-isolation-trials", "--disable-gpu"],
"excludeSwitches" => ["enable-logging"],
},
)
Capybara::Selenium::Driver.new(app, :browser => :chrome, :desired_capabilities => caps)
end
@thienhv
thienhv / safe_s3.rb
Created December 23, 2021 08:37 — forked from pmontrasio/safe_s3.rb
Compress a file, encrypt it, upload it to S3. Download, decrypt, uncompress.
#!/bin/env/ruby
# gem "aws-sdk", "~> 2"
require "rubygems"
require "zlib"
require "rubygems/package"
require "securerandom"
gem "aws-sdk"
require "aws-sdk"