Skip to content

Instantly share code, notes, and snippets.

View conanak99's full-sized avatar

Phạm Huy Hoàng conanak99

View GitHub Profile
// 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%$#@#')
// 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
// Đọ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)
// 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)
List<Course> courses = new List<Course>();
courses.Add(new Course
{
ID = 1,
Subject = "LINQ Tutorials",
Rank = 5
});
courses.Add(new Course
{
ID = 2,
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
const store = new Vuex.Store({
state: {
players: {},
status: WAITING_FOR_BET,
dices: [1, 2, 3],
board: {
1: {},
2: {},
3: {},
4: {},
<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"
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 => {
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 });
});