Skip to content

Instantly share code, notes, and snippets.

View oNguyenNgocTrung's full-sized avatar

Nguyen Ngoc Trung oNguyenNgocTrung

View GitHub Profile
class CreatePeople < ActiveRecord::Migration
def change
create_table :people do |t|
t.string :name
t.references :parent, index: true
t.timestamps null: false
end
end
end
@oNguyenNgocTrung
oNguyenNgocTrung / Answer.txt
Created September 23, 2015 04:07
Question 2
Dùng "+" thì mỗi lần create một object mới chõ mỗi lần dùng, còn "concast" làm việc với chính nó nên việc sử dụng "+"
sẽ cho tóc độ xử lí chậm hơn.
@oNguyenNgocTrung
oNguyenNgocTrung / answer.txt
Created September 23, 2015 07:22
Question 1
- Ý tưởng của em là khởi tạo mảng mới chứa các điểm X. Sau đó duyệt qua từng hàng.
so sánh hoành độ của các điểm X của hàng đang duyệt với các điểm trong mảng các ao.
Nếu chênh nhau 1 thì nạp thêm điểm mới vào ao kia.
ví dụ như bài trên:
Ta có mảng arr_land chứa tất cả các ao
- Duyệt Row 1 : có Ao1 = {(0,0)}, Ao2 = {(0,9), (0,10)} --> add Ao1, Ao2 vào mảng arr_land
- Duyệt Row 2: có Ao3 = {(1,1),{1,2),(1,3)}, Ao4 = {(1,9),(1,10),(1,11)}
Xet Ao3 có phần tử (1,1) có chung đỉnh vs đỉnh (0,0) của Ao1 nên gộp 2 mảng Ao1 và Ao3 lại--> tượng tư vs Ao4
vậy ta vẫn có magr arr_land chứa 2 ao Ao1 {(0,0),(1,1),{1,2),(1,3)} và Ao2 {(0,9), (0,10), (1,9),(1,10),(1,11) }
@oNguyenNgocTrung
oNguyenNgocTrung / rspec_model_testing_template.rb
Created August 18, 2017 07:20 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
@oNguyenNgocTrung
oNguyenNgocTrung / export.js
Last active May 19, 2018 06:48
Export csv use like post facebook
function convertArrayOfObjectsToCSV(args) {
var result, ctr, keys, columnDelimiter, lineDelimiter, data;
data = args.data || null;
if (data == null || !data.length) {
return null;
}
columnDelimiter = args.columnDelimiter || ',';
lineDelimiter = args.lineDelimiter || '\n';
@oNguyenNgocTrung
oNguyenNgocTrung / spacemacs-keybindings
Created May 22, 2018 04:02 — forked from adham90/spacemacs-keybindings
spacemacs keybindings that i need to learn
SPC s c remove highlight
**** Files manipulations key bindings
Files manipulation commands (start with ~f~):
| Key Binding | Description |
|-------------+----------------------------------------------------------------|
| ~SPC f c~ | copy current file to a different location |
| ~SPC f C d~ | convert file from unix to dos encoding |
| ~SPC f C u~ | convert file from dos to unix encoding |
@oNguyenNgocTrung
oNguyenNgocTrung / ripgrep-in-emacs.md
Created May 29, 2018 15:39 — forked from pesterhazy/ripgrep-in-emacs.md
Using ripgrep in Emacs using helm-ag (Spacemacs)

Why

Ripgrep is a fast search tool like grep. It's mostly a drop-in replacement for ag, also know as the Silver Searcher.

helm-ag is a fantastic package for Emacs that allows you to display search results in a buffer. You can also jump to locations of matches. Despite the name, helm-ag works with ripgrep (rg) as well as with ag.

How

@oNguyenNgocTrung
oNguyenNgocTrung / init.el
Created June 15, 2018 08:48
Emacs config
;;;; SPEED UP EMACS ====================================
;; Decrease the number of garbage collection invocations
(setq gc-cons-threshold 10000000)
(add-hook 'emacs-startup-hook 'my/set-gc-threshold)
(defun my/set-gc-threshold ()
"Reset `gc-cons-threshold' to its default value."
(setq gc-cons-threshold 800000))
;; Package configs
(require 'package)
@oNguyenNgocTrung
oNguyenNgocTrung / ubuntu_config.md
Last active July 29, 2018 16:42
Ubuntu Config

Install Source Code Pro

[ -d /usr/share/fonts/opentype ] || sudo mkdir /usr/share/fonts/opentype
sudo git clone --depth 1 --branch release https://github.com/adobe-fonts/source-code-pro.git /usr/share/fonts/opentype/scp
sudo fc-cache -f -v

Install Emacs