docker-compose for Elasticsearch & Kibana

Create a file docker-compose.yml with the following content:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
version: '3'

services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.2.0
container_name: elasticsearch_local
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- discovery.type=single-node
- http.cors.enabled=true
- http.cors.allow-credentials=true
- http.cors.allow-headers=X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization
- http.cors.allow-origin=/https?:\/\/localhost(:[0-9]+)?/
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- esnet
kibana:
image: docker.elastic.co/kibana/kibana:7.2.0
container_name: kibana_1
environment:
- "SERVER_NAME=kibana"
- "ELASTICSEARCH_HOSTS=http://elasticsearch:9200"
ports:
- 5601:5601
networks:
- esnet
restart: "unless-stopped"

volumes:
esdata1:
driver: local

networks:
esnet:

Read More

jQuery infinite scroll articles

Quite often, we have seen a lot of news site (e.g. forbes.com),
when you scrolled until end of the article, it will shows another article.

Read More

How to setup Google Optimize server side test with GTM

Recently I come across A/B testing, to see which algorithm is most effective to trigger user clicks.

Here I use Google Optimize, setup via
Google Tag Manager to do the job.

Read More

Setup OpenVPN in AWS for RDS access

When we use AWS, often we will use RDS, for security reason, is better to not to expose to public.

RDS settings

Read More

Laravel auto deployment with GitLab CI/CD

I’ve been heard of continuous integration long ago, thus I decide to give it a try.
I found the official guideline from GitLab itself, and it looks quite complicated.
End up I follow this article.

Read More

window.onbeforeunload trigger ajax request

Initially I was using jQuery.ajax call to send a request to server before user
leave the page.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
window.onbeforeunload = function(evt) {
const endpoint = '/lock/end-timestamp.php';
$.ajax({
url: endpoint,
dataType: 'json',
type: 'post',
async: false, // synchronous request
data: {
_token: $('meta[name="csrf-token"]').attr('content'),
param1: 'data1',
param2: 'data2',
},
});
};

Read More

Use Google Analytics API with Laravel 5

No doubt that Google is very powerful. I’ve been researching for
Google Analytics (GA) API for quite sometime, due to it’s complex documentation
(somehow I think is very hard to find what I need).

Read More

DataTable re-order rows

In CMS, often the navigation menu is editable in backend, and can change the order.
Let’s see how to implement using DataTable.

Read More

Laravel - Integrate oEmbed into TinyMCE

oEmbed is a kind of standard to retrieve 3rd party site info.

Example, in rich editor like TinyMCE, if want to embed
a YouTube video, what we usually do is

Read More

Laravel Eloquent join with subquery

Let’s take the query from this post as example

1
2
3
4
5
6
7
8
9
10
11
12
SELECT books.id AS book_id
, books.isbn
, books.title
, t_borrowers.user_ids
FROM books
LEFT JOIN (
SELECT user_books.book_id
, CONCAT('#', GROUP_CONCAT(user_books.user_id SEPARATOR '#,#'), '#') AS user_ids
FROM user_books
GROUP BY user_books.book_id
) AS t_borrowers ON t_borrowers.book_id = books.id
WHERE (t_borrowers.user_ids LIKE '%#1#%' OR t_borrowers.user_ids LIKE '%#3#%');

Read More