Skip to content

Instantly share code, notes, and snippets.

View winhvu's full-sized avatar

Vu Nguyen winhvu

  • Stockholm, Sweden
View GitHub Profile
@winhvu
winhvu / clean_code.md
Created December 25, 2023 07:01 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@winhvu
winhvu / regex.cpp
Created October 27, 2016 06:52
Regular expression in C++ and Raw string
#include <iostream>
#include <regex>
using namespace std;
int main() {
regex email_pattern(R"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)");
string valid_email("swift@codeforces.com"), invalid_email("hello world");
@winhvu
winhvu / .pythonrc
Created October 27, 2016 04:56
enable syntax completion
# ~/.pythonrc
# enable syntax completion
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
ls() {
if [[ $@ == "-la" ]]; then
command ls -la | more
else
command ls "$@"
fi
}
>> MOVE
C-f Move forward a character
C-b Move backward a character
M-f Move forward a word
M-b Move backward a word
C-n Move to next line
C-p Move to previous line
# Remove all matched ones
rm -f $(find / -name core)
# Convert date format
$Prev_date="Wed Dec 25 06:35:02 EST 2013"
#solution to read this date as 2013-12-25 and store it in a variable.
a=$(printf '%s\n' "$Prev_date" | awk '{
printf "%04d-%02d-%02d\n", $6, \
(index("JanFebMarAprMayJunJulAugSepOctNovDec",$2)+2)/3,$3}')
@winhvu
winhvu / sed
Created January 13, 2015 10:41
# Use & to get the matched pattern
% echo "123 abc" | sed 's/[0-9]*/& &/'
123 123 abc
test expression
or
[ expression ]
# Several built-in operators can be used with the test command. These operators can be classified into four groups:
integer operators, string operators, file operators, and logical operators.
#Table 2: The test command's integer operators.
Operator Meaning
int1 -eq int2 Returns True if int1 is equal to int2.
#!/bin/bash
# Built-in shell variables.
# Variable Use
$# Stores the number of command-line arguments that were passed to the shell program.
$? Stores the exit value of the last command that was executed.
$0 Stores the first word of the entered command (the name of the shell program).
$* Stores all the arguments that were entered on the command line ($1 $2 ...).
"$@" Stores all the arguments that were entered on the command line, individually quoted ("$1" "$2" ...).
# ===
CUR_DIR = $(shell pwd)
SUB_DIR =
SUB_DIR += $(CUR_DIR)/lib \
$(CUR_DIR)/app
.PHONY: all