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 / userdata.sh
Last active February 4, 2025 06:36
install docker aws ec2 user data for amazon linux
#!/bin/bash
# Update the system
dnf update -y
# Install docker package
dnf install docker -y
# Start Docker service
systemctl start docker
@thorvn
thorvn / sodoku.c
Last active October 4, 2018 15:41
#include <stdio.h>
#include <stdlib.h>
int main() {
int n = 3;
int m = 3;
int a[3][3] = { 0 };
a[1][1] = 5;
int x = 5;
@thorvn
thorvn / measure.rb
Created September 16, 2018 15:41
measure Ruby performance
def measure(no_gc = true, &block)
if no_gc
GC.disable
else
GC.start
end
memory_before = `ps -o rss= -p #{Process.pid}`.to_i/1024
gc_stat_before = GC.stat
time = Benchmark.realtime do
yield
@thorvn
thorvn / 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;"
@thorvn
thorvn / benchmark.rb
Created August 21, 2018 04:48
Benchmark ruby
sizes = [10, 50, 100, 1000]
sizes.each do |size|
array = size.times.map { |i| rand(size) }
threshold = size / 2
Benchmark.bmbm(2) do |x|
x.report("select #{size}") do
array.select { |item| item > threshold }
.each { |item| item * item }
@thorvn
thorvn / mysql_note.md
Created July 30, 2018 04:38
mysql note

Change password

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';
@thorvn
thorvn / 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) }
@thorvn
thorvn / Install_Emacs.md
Last active November 30, 2019 00:12
Install emacs 26.1 on Ubuntu 18.03

Emacs dependencies

sudo apt-get install build-essential texinfo libx11-dev libxpm-dev libjpeg-dev libpng-dev libgif-dev libtiff-dev libgtk2.0-dev libncurses-dev libxpm-dev automake autoconf

Build emacs

mkdir emacs
cd emacs
@thorvn
thorvn / 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