Skip to content

Instantly share code, notes, and snippets.

View tankhuu's full-sized avatar

Tan Khuu tankhuu

  • Ho Chi Minh, Viet Nam
View GitHub Profile
@tankhuu
tankhuu / react_app_initiation.md
Last active December 18, 2018 15:56
React Application Initiation
@tankhuu
tankhuu / rfm_analysis.js
Created December 17, 2018 04:01
RFM Analysis in NodeJS
import {Meteor} from 'meteor/meteor';
import {check, Match} from 'meteor/check';
import moment from 'moment';
import bodybuilder from 'bodybuilder';
import {Promise} from 'meteor/promise';
import RequestPromise from 'request-promise';
import _ from 'lodash';
/* Collections */
import {RFMScoreBoard, RFMTopTen} from '/imports/api/collections/rfm';
@tankhuu
tankhuu / amazon_linux_install_varnish4.1.10.sh
Created December 12, 2018 10:13
Amazon Linux Install Varnish 4.1.10
sudo yum -y install autoconf automake jemalloc-devel libedit-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx graphviz
curl -s https://packagecloud.io/install/repositories/varnishcache/varnish41/script.rpm.sh | sudo bash
wget --content-disposition https://packagecloud.io/varnishcache/varnish41/packages/el/6/varnish-4.1.10-1.el6.x86_64.rpm/download.rpm
sudo rpm -Uvh varnish-4.1.10-1.el6.x86_64.rpm
/usr/sbin/varnishd -V
@tankhuu
tankhuu / elasticsearch-define-templates.json
Created December 11, 2018 05:39
Elasticsearch Templates
# DELETE _template/mysql_slow
PUT _template/mysql_slow
{
"order": 0,
"template": "mysql-slow-*",
"settings": {
"index": {
"number_of_shards": "1"
}
},
#!/usr/bin/env bash
# VARIABLES #
AWSAccessKeyId=\$1
AWSSecretKey=\$2
CRON_DIR=/var/spool/cron
# EXECUTE #
# Install libs
sudo yum install -y unzip perl-libwww-perl perl-libdatetime-perl perl-Sys-Syslog perl-DateTime-TimeZone perl-LWP-Protocol-https perl-Crypt-SSLeay
# Setup AWS mon scripts
mkdir ~/aws
sudo yum install gcc-c++ pcre-devel zlib-devel make unzip openssl-devel libuuid-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools-devel
#[check the release notes for the latest version]
NPS_VERSION=1.13.35.2-stable
cd
wget https://github.com/apache/incubator-pagespeed-ngx/archive/v${NPS_VERSION}.zip
unzip v${NPS_VERSION}.zip
nps_dir=$(find . -name "*pagespeed-ngx-${NPS_VERSION}" -type d)
cd "$nps_dir"
NPS_RELEASE_NUMBER=${NPS_VERSION/beta/}
NPS_RELEASE_NUMBER=${NPS_VERSION/stable/}
@tankhuu
tankhuu / hex.js
Created October 24, 2018 15:03 — forked from valentinkostadinov/hex.js
JavaScript HEX encoding
function toHex(s) {
// utf8 to latin1
var s = unescape(encodeURIComponent(s))
var h = ''
for (var i = 0; i < s.length; i++) {
h += s.charCodeAt(i).toString(16)
}
return h
}
# Source From: https://www.jeremydaly.com/access-aws-vpc-based-elasticsearch-cluster-locally/
# You need to have an EC2 instance running in the same VPC as your Elasticsearch cluster.
# If you don’t, fire up a micro Linux instance with a secure key pair.
# NOTE: Make sure your instance’s security group has access to the Elasticsearch cluster and
# that your Elasticsearch cluster’s access policy uses the “Do not require signing request with IAM credential” template.
# At local Client
## Create SSH Tunnel
cat << EOF > ~/.ssh/config
# Elasticsearch Tunnel
# For using epel packages
sudo yum install nodejs npm --enablerepo=epel
# For disable SSL if error occur: "npm ERR! code UNABLE_TO_GET_ISSUER_CERT_LOCALLY"
sudo npm config set strict-ssl=false
# Install npm & version control
sudo npm install -g n
sudo npm install -g npm
# Install specific nodejs version
sudo n v10.8.0
ssh -i ~/.ssh/rsa_key.pem -t ec2-user@xxx.xxx.xxx.xxx 'ssh -i ~/.ssh/rsa_key.pem ec2-user@xxx.xxx.xxx.xxx'