Skip to content

Instantly share code, notes, and snippets.

View trantuanckc's full-sized avatar

Tran Minh Tuan trantuanckc

View GitHub Profile

Rails 5.0 Rails 5.1+ changed? → saved_change_to? _was → _before_last_save changed? → saved_changes? changed_attributes → saved_changes.transform_values(&:first)

Model callbacks behavior After Rails 4.x release, some changes were made on callbacks to split update on the model before and after writing data to the database. We had to be careful to use the correct helpers: _changed? for after_save callbacks, and previous_changes[:] for after_commit callbacks:

@trantuanckc
trantuanckc / Tran Minh Tuan
Last active July 30, 2020 15:43
IWA-Interview
# Assignment
## Environment
### Backend
- Ruby 2.6.3
- Rails 6.0.3.2
- PostgreSQL) 12.3
### Frontend
- Angular: 10.0.5
@trantuanckc
trantuanckc / v1.rb
Created July 29, 2020 09:51 — forked from aishek/v1.rb
grape error handling
# app/controllers/api/v1.rb
class Api::V1 < Grape::API
class Grape::Middleware::Error
def error_message(code, text)
{
:error => {
:code => code,
:message => text
}
@trantuanckc
trantuanckc / splice-object-array.js
Created July 29, 2020 03:39 — forked from scottopolis/splice-object-array.js
Remove object from array of objects in Javascript
// source: http://stackoverflow.com/questions/16491758/remove-objects-from-array-by-object-property
// we have an array of objects, we want to remove one object using only the id property
var apps = [{id:34,name:'My App',another:'thing'},{id:37,name:'My New App',another:'things'}];
// get index of object with id:37
var removeIndex = apps.map(function(item) { return item.id; }).indexOf(37);
// remove object
apps.splice(removeIndex, 1);
@trantuanckc
trantuanckc / Gemfile
Created June 17, 2020 04:21 — forked from phund/Gemfile
Tool translate a erb file
source 'https://rubygems.org'
gem 'mechanize'
@trantuanckc
trantuanckc / gulpfile.js
Created August 20, 2019 16:03 — forked from michalochman/gulpfile.js
gulp.js: babelify + browserify + sourcemaps
/* jshint strict: false */
/* globals require, console */
var gulp = require('gulp');
var exit = require('gulp-exit');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
{
"editor.tabSize": 2,
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"files.trimTrailingWhitespace": true,
"sublimeTextKeymap.promptV3Features": true,
"editor.multiCursorModifier": "ctrlCmd",
"editor.snippetSuggestions": "top",
"editor.formatOnPaste": true,
"editor.fontSize": 15,
"ruby.rubocop.executePath": "/Users/t_m_tran/.rvm/gems/ruby-2.4.2/bin/",
@trantuanckc
trantuanckc / capybara cheat sheet
Last active February 4, 2018 05:18 — forked from zhengjia/capybara cheat sheet
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@trantuanckc
trantuanckc / sublime-text-3-setup.md
Created August 13, 2016 05:28 — forked from ijy/sublime-text-3-setup.md
My Sublime Text 3 setup.

Sublime Text 3 Setup

Install Package Control

Install Package Control for easy package management.

  1. Open the console with Ctrl+`
  2. Paste in the following: