View copy_paste_fix.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tách thành function riêng | |
// Trim and upper case | |
function chimUp(input) { | |
// Có bug chỉ cần sửa 1 chỗ | |
return input.trim().replace(/[^a-zA-Z ]/g, "").toUpperCase() | |
} | |
// Có thể dễ dàng dùng mà không cần copy paste | |
let input = chimUp('abd4%$#@#') |
View copy_paste.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Code bỏ kí tự đặc biệt và viết hoa | |
let input = 'abd4%$#@#'; | |
input = input.trim().replace(/[^a-zA-Z ]/g, "").toUpperCase() | |
// Đoạn code khác ... | |
// Copy lần 1 | |
const username = 'ahihi-de-em-di' | |
const trimmedUsername = username.trim().replace(/[^a-zA-Z ]/g, "").toUpperCase() | |
// ...Copy tiếp logic qua đoạn khác |
View hard_core_fix.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Đọc DB_CONNECTION từ biến môi trường hoặc file Config | |
const DB_CONNECTION = Config.Get('DB_CONNECTION') || env['DB_CONNECTION'] | |
const DB_CONNECTION_POLL = 4 // Dùng 4 vì lý do blah blah | |
const DB_NAME = 'db_codedao_blog' // Tách thành biên để biết đây là tên DB | |
DB.connect(DB_CONNECTION, DB_NAME, DB_CONNECTION_POLL) |
View hard_core.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hard code DB Connection | |
const DB_CONNECTION = 'localhost://4090;username=hoangdeptrai;password=codedao' | |
// Magic number: 4 là gì, tại sao dùng 4 mà không phải số khác | |
DB.connect(DB_CONNECTION, 'db_codedao_blog', 4) |
View linq.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<Course> courses = new List<Course>(); | |
courses.Add(new Course | |
{ | |
ID = 1, | |
Subject = "LINQ Tutorials", | |
Rank = 5 | |
}); | |
courses.Add(new Course | |
{ | |
ID = 2, |
View finish-game.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
finishGame({ commit, state }) { | |
commit('removeLosers'); | |
// Đếm những quân xí ngầu thắng | |
var diceDic = countBy(state.dices, dice => dice); | |
for (const key in diceDic) { | |
const multiplier = diceDic[key] + 1; | |
const winners = Object.values(state.board[key]); | |
// Cộng điềm cho những người thắng |
View state.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const store = new Vuex.Store({ | |
state: { | |
players: {}, | |
status: WAITING_FOR_BET, | |
dices: [1, 2, 3], | |
board: { | |
1: {}, | |
2: {}, | |
3: {}, | |
4: {}, |
View table.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div> | |
<div class="bc-table"> | |
<!-- Ảnh bầu cua --> | |
<img src="./../assets/baucua.jpg" alt class="image bc-image" /> | |
<div class="bc-overlay"> | |
<!-- 6 cells tương ứng với 6 con --> | |
<div class="boards" :key="key" v-for="(cell, key) in board"> | |
<transition-group | |
tag="div" | |
enter-active-class="animated bounceInDown" |
View get-bet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getBetFromComment(comment) { | |
const cleanedComment = textParser.charToNumber( | |
textParser.removeUnicode(comment.toLowerCase())); | |
const regex = /(\d+)( |-)?(cop|bau|ga|tom|ca|cua)/; | |
const matches = cleanedComment.match(regex); | |
if (!matches) return []; | |
const bets = matches.map(match => { |
View client-socket.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io from 'socket.io-client'; | |
const socket = io('http://localhost:3002'); | |
socket.on('connect', () => { console.log('connected') }); | |
socket.on('newBet', function(newBet) { | |
const { id, name, avatar, bet, choice } = newBet; | |
const player = new Player(id, name, avatar); | |
store.dispatch('placeBet', { player, bet, choice }); | |
}); |
NewerOlder