Skip to content

Instantly share code, notes, and snippets.

View sajidzaman's full-sized avatar
🎯
Focusing

Sajid Badi-uz-zaman sajidzaman

🎯
Focusing
View GitHub Profile
@sajidzaman
sajidzaman / datetime_timezones.php
Created October 30, 2018 12:56 — forked from sobstel/datetime_timezones.php
PHP: Converting DateTime between timezones
<?php
// now
$date = date_create('2010-12-31 22:00:01', timezone_open('Europe/Amsterdam'));
// Buenos Aires
date_timezone_set($date, timezone_open('America/Argentina/Buenos_Aires'));
echo $date->format('Y-m-d H:i:s');
// 2010-12-31 18:00:01
// UTC
/**
* Be sure to include library scripts in this order. Can be placed either
* in the header or footer.
*/
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-infinitescroll/2.0b2.120519/jquery.infinitescroll.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/masonry/3.1.2/masonry.pkgd.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.min.js"></script>
@sajidzaman
sajidzaman / slugify.js
Created October 3, 2017 11:07 — forked from mathewbyrne/slugify.js
Javascript Slugify
function slugify(text)
{
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@sajidzaman
sajidzaman / Aggregation
Last active August 17, 2017 07:06
Aggregation in Elastic search
Each Aggregation makes buckets, it shows the number of documents
GET /vehicles/cars/_search
{
"aggs": {
"popular_cars" : {
"terms" : {
"field" : "make.keyword"
},
@sajidzaman
sajidzaman / Pagination and sorting
Created August 17, 2017 06:18
Pagination and sorting in elastic search
GET /vehicles/cars/_search
{
"from": 0,
"size" : 5,
"query": {
"match_all": {}
},
"sort": [
{ "price": { "order": "desc"} }
]
@sajidzaman
sajidzaman / Field Booster
Created August 16, 2017 13:20
Field Booster in elastic search to boost the releavance
"course_description^2"
will increaes the field relevance
@sajidzaman
sajidzaman / Filter
Last active August 16, 2017 13:13
Elastic search Filters
GET courses/_search
{
"query" :{
"bool":{
"filter" :{
"match": {"name": "accounting"}
}
}
}
}
@sajidzaman
sajidzaman / Match phrase
Created August 16, 2017 12:58
Elastic search queries
"query" :{
"match_phrase_prefix": {
"course_description": "from the business school taken by fin"
}
}
"query" :{
"match_phrase": {
"course_description": "from the business school taken by fin"
}
@sajidzaman
sajidzaman / gist:66ca0cf1c62a5c1a81634cf862699c3a
Created August 16, 2017 12:43
Multi match elastic search query
GET courses/_search
{
"query" :{
"multi_match": {
"query": "accounting",
"fields": ["name","professor.department"]
}
}
}
@sajidzaman
sajidzaman / gist:27e7720929a7a1be704c9d6fe8fc0ce8
Created August 16, 2017 12:20
Elastic search must query
GET courses/_search
{
"query" :{
"bool": {
"must": [
{"match" : {"name" : "accounting"}}
],
"must_not": [
{"match" : {"professor.name": "bill"}}