Skip to content

Instantly share code, notes, and snippets.

View thanhpk's full-sized avatar

Thanh thanhpk

View GitHub Profile
@thanhpk
thanhpk / addjquery.js
Last active June 23, 2016 06:43
Add jQuery to a webpage using google console programmatically
var loadjQuery = function(cb){
if(typeof(jQuery) == 'undefined'){
var scr = document.createElement('script');
scr.setAttribute('type', 'text/javascript');
scr.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js');
if(scr.readyState){
scr.onreadystatechange = function(){
if(scr.readyState === 'complete' || scr.readyState === 'loaded'){
scr.onreadystatechange = null;
@thanhpk
thanhpk / listuserapi.js
Last active July 6, 2016 17:09
API list user
GET /segment/{appid}/{segmentid}/listUser/{page}/{field1}/{field2}
{appid} : id của ứng dụng
{segmentid}: segment id
{page}: dùng trong phân trang, {page} quy định số thứ tự của trang ( mỗi trang có cố định 100 phần tử)
{field1}: code của filter1 ví dụ: _os, age, _revenue
{field2}: [có thể bỏ trổng] code của filter2
kết quả trả ra là mảng bản ghi user dưới dạng json
@thanhpk
thanhpk / meotricsapi.md
Last active August 30, 2016 15:18
Meotrics nodejs api

Segmentation

  1. List segmentations of an $appid
$segments = MtHttp::get('segment/' . $appid);

Properties

  1. Type definition
@thanhpk
thanhpk / dupicate.js
Created September 21, 2016 03:37
Duplicate location finder
var n = 0;
var myCursor = db.warehouseproducts.find();
while (myCursor.hasNext()) {
var doc = myCursor.next();
var locationMap = {};
for (var i = 0 ; i < doc.locations.length; i++)
if (locationMap[doc.locations[i].location.str] !== undefined) {
printjson(doc._id);
n++;
break;
@thanhpk
thanhpk / cheatsheet.md
Created January 7, 2017 16:55
emacs map

Emacs

M-x revert-buffer

C-t: swich frame M-x set-frame-name: set frame name

Create a new terminal

M-x term: create a new term C-c C-j: switch to line mode C-c C-k: switch to char mode

*1 A die at 2
B cant send message 5 -> tell C to discard the previous package
message is stored in B, if A is the root -> B discard the message
else
2 B down at 2
A wait for ACK and retry on new B
*3 A down at 3
@thanhpk
thanhpk / addjquery
Last active April 28, 2017 13:34
Add JQuery programatically to a page use Google Console
function addJquery(cb) {
if (typeof(jQuery) !== 'undefined') return;
var url = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
var scr = document.createElement('script'); scr.setAttribute('type', 'text/javascript'); scr.setAttribute('src', url);
var head = document.getElementsByTagName('head')[0]; head.insertBefore(scr, head.firstChild);
}
addJquery();
@thanhpk
thanhpk / Vagrantfile
Last active November 6, 2017 12:07
Vagranfile to run kubenetes locally
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network "public_network"
config.vm.provider "virtualbox" do |vb|
vb.memory = "2048"
end
config.vm.hostname = "kube"
config.vm.provision "shell", inline: <<-SHELL
@thanhpk
thanhpk / gist:782d665e379516f8f729b6d5fd599376
Created February 12, 2018 05:36
watch kubernetes get pod
watch -n 1 'echo "GKE===================" && kubectl get pod --context="gke_subiz-version-4_us-central1-a_app-cluster-1" && echo "DEV===================" && kubectl get pod'
@thanhpk
thanhpk / zookeeper.md
Created July 13, 2018 04:01
Get insight about zookeer cluster

echo stat | nc localhost 2181

Zookeeper version: 3.4.8-1--1, built on Fri, 26 Feb 2016 14:51:43 +0100
Clients:
 /10.128.0.10:23356[1](queued=0,recved=1612644,sent=1612660)
 /10.128.0.9:55534[1](queued=0,recved=400,sent=400)
 /10.128.0.8:25044[1](queued=0,recved=400,sent=400)
 /127.0.0.1:27466[0](queued=0,recved=1,sent=0)

Latency min/avg/max: 0/0/444