Skip to content

Instantly share code, notes, and snippets.

View thorvn's full-sized avatar
:octocat:
🚀 🚀

Tho Vo thorvn

:octocat:
🚀 🚀
View GitHub Profile
@thorvn
thorvn / CONDING_RULE.md
Last active July 20, 2018 06:39
Conding convention

1. Hạn chế việc sử dụng if else lồng nhau. Ở đầu function nên return các case sai sau đó mới viết logic cho function

2. Khi viết SQL không được nối chuỗi mà phải sử dụng param truyền vào câu truy vấn.

3. Sử dụng Active record hoặc Arel over raw queries

Example:

    # unless ids.blank?
    #   sql = "DELETE FROM links WHERE links.user_id = #{user_id.to_s} AND links.id IN (#{ids.to_s})"
    #   connection.execute(sql)
    # end
 return if ids.blank?
@thorvn
thorvn / install_BWAPP.md
Last active July 14, 2018 04:25
Install BWAPP

1. Install XAMPP

Use PHP 5.x, not use PHP 7.x, because some function of BWAPP can't run.

chmod +x xampp-linux-x64-5.6.36-0-installer.run
sudo ./xampp-linux-x64-5.6.36-0-installer.run

2. Install BWAPP

After download BWAPP, extract and copy add dir to /opt/lampp/htdocs/ (dir install XAMPP).

Show top 10 comments

history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a; }' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n10

Delete all local branch except master and develop

git branch | grep -v "(master\|develop)" | xargs git branch -D'
@thorvn
thorvn / connect_ec2.md
Last active June 10, 2018 16:38
How to connect PostgreSQL on EC2

Update pg_hba.conf as described in the previous section:

sudo vim /etc/postgresql/9.1/main/pg_hba.conf

Update the bottom of the file, which will read something like this, by default:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
@thorvn
thorvn / *.html
Last active May 16, 2018 10:38
Custom checkbox
<li ng-repeat="group in groups" ng-class="{active: filterGroupIds[group.id]}">
<div class="checkboxgroup whitebg large-custom">
<input type="checkbox" id="groupsSelected{{$index}}" ng-model="group.selected" ng-value="group.id">
<label class="fake-input" for="groupsSelected{{$index}}"></label>
<label for="groupsSelected{{$index}}">{{ group.name }}</label>
</div>
</li>
@thorvn
thorvn / ci.sh
Last active May 8, 2018 15:01
Setup shell for Jenkins CI
cd /var/lib/jenkins/workspace/rails_ci_1
ruby -v
gem install bundler
bundle install
@thorvn
thorvn / curl.sh
Created April 9, 2018 08:44
Curl multipart/form-data
curl -X POST -H "Content-Type: multipart/form-data" -F cloud_storages[]["bookmark_data"]=@arch_screenshot.png -F cloud_storages[]["real_filename"]=test_1 -F cloud_storages[]["ext"]=jpg -F cloud_storages[]["bookmark_data"]=@arch_screenshot.png -F cloud_storages[]["real_filename"]=test_2 -F cloud_storages[]["ext"]=png localhost:3000/api/v2/cloud_storages?keyapi=03da0b83c3dab8e2a48d28d1944b08dd
@thorvn
thorvn / Dockerfile
Last active April 5, 2018 16:35
Docker alpine + Rails + Postgresql
FROM ruby:2.4.1-alpine3.6
RUN apk add --update build-base libffi-dev libxml2-dev libxslt-dev postgresql-dev nodejs tzdata bash
ENV RAILS_ENV=production \
APP_HOME=/app
ENV BUNDLE_PATH /box
RUN mkdir -p $APP_HOME
@thorvn
thorvn / Dockerfile
Created October 9, 2017 15:59
Speedup docker
FROM ruby:2.4.1-alpine3.6
RUN apk add --update build-base libffi-dev libxml2-dev libxslt-dev postgresql-dev nodejs tzdata bash
ENV RAILS_ENV=production \
APP_HOME=/app \
ENV BUNDLE_PATH /bundle
RUN mkdir -p $APP_HOME
@thorvn
thorvn / .drink_water_linux.sh
Last active October 28, 2018 10:30
Send notification to remember drink water
eval "export $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME gnome-session)/environ)";
DISPLAY=:0 notify-send "Hey!!!" "Keep your back straight and remember drink water!"