Skip to content

Instantly share code, notes, and snippets.

View th0j's full-sized avatar
💭
🚀 🚀

Tho Vo th0j

💭
🚀 🚀
View GitHub Profile
@th0j
th0j / *.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>
@th0j
th0j / 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

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'
@th0j
th0j / 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).

@th0j
th0j / 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?
@th0j
th0j / access_control.rb
Created July 23, 2018 03:23
Access control in ruby
class A
protected
def protected_a
puts "Protected A"
end
private
def private_a
puts "Private A"
end
@th0j
th0j / split_sql.rb
Created July 30, 2018 03:59
Split big sql file
filename = 'flowdata_201803052230.sql'
INSERT_MATCHER = 'INSERT INTO'
file = 1
counter = 1
File.open(filename, 'r').each do |line|
next unless line.include? INSERT_MATCHER
File.open(file.to_s + '.sql', 'a+') { |file| file.write("\n" + line) }
@th0j
th0j / mysql_note.md
Created July 30, 2018 04:38
mysql note

Change password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
@th0j
th0j / import_large_sql.sh
Created September 14, 2018 01:19
Import a large sql dump file to a MySQL database from command line
#!/bin/sh
# store start date to a variable
imeron=`date`
echo "Import started: OK"
dumpfile="/home/bob/bobiras.sql"
ddl="set names utf8; "
ddl="$ddl set global net_buffer_length=1000000;"