Skip to content

Instantly share code, notes, and snippets.

View dieunb's full-sized avatar
🎯
Focusing

Dieu Nguyen dieunb

🎯
Focusing
View GitHub Profile
# Export
mysqldump -u [uname] -p[pass] db_name > db_backup.sql
# Import
mysql -u <username> -p <databasename> < <filename.sql>
# Pull file from server
scp -P 10000 -i ~/.ssh/framgia/id_rsa edu@113.164.228.14:/home/edu/ac_backup.sql ~/
#!/usr/bin/env puma
threads_max = ENV.fetch("RAILS_MAX_THREADS"){ 5 }.to_i
threads_min = ENV.fetch("RAILS_MIN_THREADS"){ 1 }.to_i
threads threads_min, threads_max
# Specifies the `port` that Puma will listen on to receive requests, default is 3000.
#
# port ENV.fetch("PORT") { 3000 }.to_i
# Specifies the `environment` that Puma will run in.
#!/usr/bin/env puma
directory "/home/deploy/wsm_production/current"
rackup "/home/deploy/wsm_production/current/config.ru"
# Default to production
rails_env = "production"
environment rails_env
@dieunb
dieunb / gist:b8db962b7f04ffb1a6e55c30e9cf38f5
Created December 1, 2016 01:58
Build JSON question data
params = []
questions = $('div[style="background-color: white; box-sizing: border-box; color: #444444; font-family: Arial, sans-serif; font-size: 16px; line-height: 25.6px; margin-bottom: 1.5em; padding: 0px; text-rendering: auto !important; vertical-align: baseline; word-wrap: break-word;"]');
questions.each(function() {
if ($(this).text().indexOf('Answers:') < 0) {
question_params = {}
question_params.content = $(this).text();
question_params.subject_id = 18;
question_params.user_id = 7;
@dieunb
dieunb / gist:28149d01510e7346cd2678199e2a2186
Created November 14, 2016 03:22
Avatar Base64 Params
{"user":{"avatar":"iVBORw0KGgoAAAANSUhEUgAAA8AAAAPACAIAAAB1tIfMAAAAYXpUWHRSYXcgcHJvZmlsZSB0eXBlIGlwdGMAAHjaPYaxEYBACARzqrAE/jkOvh40MDOw/xEN3Ju5XTmvu2T7sBRLTCzsit7PWKN0MrqAQKGc7pE2w3mwyLa/171b0iWoKg+hExPxXW453gAAARRpQ0NQaWNtAAAokWNgYOLJSc4tZhJgYMjNKykKcndSiIiMUmC/w8DIIMnAzKDJYJmYXFzgGBDgw4ATfLsGVA0El3VBZuFWhxVwpaQWJwPpP0Acl1xQVMLAwBgDZHOXlxSA2BlAtkhSNphdA2IXAR0IZE8AsdMh7CVgNRD2DrCakCBnIPsMkO2QjsROQmJD7QUB5mQjEl1NBChJrSgB0W5ODAygMIWIIsIKIcYsBsTGDAxMSxBi+YsYGCy+AsUnIMSSZjIwbG9lYJC4hRBTWcDAwN/CwLDtfHJpURnUaikgPs14kjmZdRJHNvc3AXvRQGkTxY+aE4wkrCe5sQaWx77NLqhi7dw4q2ZN5v7ay4dfGvz/DwDeQVN9MTo3JgAAIABJREFUeF7s3XmcZFV5PvDnPbe23peZYUYQUBAFNYoSIbjGxC2aX6JGTTSJiRHXxC1xRUWBEBc0LC644YJCRCEuqKjBiAYRRRAQFGTfhtlneq27nHPe3x9V1dMz0z23qru2W/V8P2NPT3tu01331r1PnXrve0RVQURERERE9TFpA4iIiIiIaDcGaCIiIiKiBjBAExERERE1gAGaiIiIiKgBDNBERERERA1ggCYiIiIiagADNBERERFRAxigiYiIiIgawABNRERERNQABmgiIiIiogYwQBMRERERNYABmoiIiIioAQzQREREREQNYIAmIiIiImoAAzQRERERUQMYoImIiIiIGsAATURERETUAAZoIiIiIqIGMEATERERETWAAZqIiIiIqAEM0EREREREDWCAJiIiIiJqAAM0EREREVEDG
@dieunb
dieunb / Jenkins script build rails project
Created November 11, 2016 06:18
Jenkins script build rails project
#!/bin/bash -l
mkdir -p reports/xml
#source /var/jenkins/.env
rvm use 2.3.0
RAILS_ENV=test
if [ ! bundle exec gem list bundler -i ];
@dieunb
dieunb / gist:80f5ca4360f7f651c2ce562ac7cba096
Created September 21, 2016 11:41 — forked from TeWu/gist:1234573
TCP client and multithreaded server in 14 lines of Ruby code

TCP client and multithreaded server in 14 lines of Ruby code

Server:

require "socket"
server = TCPServer.open(2626)
loop do
	Thread.fork(server.accept) do |client| 
 client.puts("Hello, I'm Ruby TCP server", "I'm disconnecting, bye :*")
@dieunb
dieunb / unicorn.rb
Created August 30, 2016 07:51
Rails unicorn config file
rails_env = ENV["RAILS_ENV"] || "development"
workers_procs = {production: 4, staging: 2}
workers_procs.default = 2
worker_processes workers_procs[rails_env.to_sym]
app_directory = "/home/nguyen.binh.dieu/ranking_#{rails_env}/current"
working_directory app_directory # available in 0.94.0+
listen "#{app_directory}/tmp/sockets/unicorn.sock", backlog: 128
@dieunb
dieunb / copy data from table of database 1 to table of database 2
Last active August 30, 2016 07:52
Copy table with selected fields from table to table of other database
INSERT INTO hr_ranking_development.users (`email`, `display_name`, `uid`, `division_id`, `section_id`, `group_id`, `team_id`, `join_date`, `resigned_date`, `position`, `created_at`, `updated_at`, `avatar`) SELECT `email`, `display_name`, `uid`, `division_id`, `section_id`, `group_id`, `team_id`, `join_date`, `resigned_date`, `position`, `created_at`, `updated_at`, `avatar` FROM hr_production.users;
@dieunb
dieunb / deploy.rb
Created February 2, 2016 12:32 — forked from netzpirat/deploy.rb
Capistrano recipe to sync rails database and files within a multi stage environment
set :sync_directories, ["public/assets", "public/galleries"]
set :sync_backups, 3