Skip to content

Instantly share code, notes, and snippets.

Batuhan Bayrakci baybatu

View GitHub Profile
@baybatu
baybatu / create-rabbitmq-exchange-queue-using-rest-api.sh
Created Apr 2, 2019
Create RabbitMQ queue and exchange with binding using REST API
View create-rabbitmq-exchange-queue-using-rest-api.sh
# create exchange
curl -i -u guest:guest -H "content-type:application/json" \
-XPUT -d'{"type":"fanout","durable":true}' \
http://localhost:15672/api/exchanges/%2f/my.exchange.name
# create queue
curl -i -u guest:guest -H "content-type:application/json" \
-XPUT -d'{"durable":true,"arguments":{"x-dead-letter-exchange":"", "x-dead-letter-routing-key": "my.queue.dead-letter"}}' \
http://localhost:15672/api/queues/%2f/my.queue
@baybatu
baybatu / split-into-subarrays.js
Last active Mar 30, 2019
Splitting array into list of subarrays in javascript
View split-into-subarrays.js
/*
* Splits array into subarrays.
* count parameter indicates that how many item per subarray contains.
* Example usage: splitIntoSubArray([1,2,3,4,5], 2) -> [[1, 2], [3, 4], [5]]
*/
function splitIntoSubArray(arr, count) {
var newArray = [];
while (arr.length > 0) {
newArray.push(arr.splice(0, count));
}
@baybatu
baybatu / SpringCouchbaseIdGeneration.java
Created Mar 23, 2019
spring-data-couchbase ile otomatik document ID üretimi
View SpringCouchbaseIdGeneration.java
@Document
public class OrnekDokuman {
@Id
@GeneratedValue(strategy = GenerationStrategy.UNIQUE) // UUID
String id;
}
@baybatu
baybatu / attach-listener-to-push-method.js
Last active Mar 17, 2019
Attach event listener to Array push method call
View attach-listener-to-push-method.js
var eventify = function(arr, callback) {
arr.push = function(e) {
Array.prototype.push.call(arr, e);
callback(arr);
};
};
var array = [1,2,3];
eventify(array, function(newArray) {
@baybatu
baybatu / json-format-using-vim-with-python.md
Last active Feb 8, 2019
JSON format in Vim using Python json.tool module
View json-format-using-vim-with-python.md
@baybatu
baybatu / liquibase-changelog.sh
Created Feb 4, 2019
Generate Liquibase changelog SQLs on CLI
View liquibase-changelog.sh
java -jar liquibase.jar \
--driver=org.postgresql.Driver \
--classpath=postgresql-9.4.1208.jre6.jar \
--changeLogFile=/workspace/product-api/src/main/resources/db/changelog.xml \
--url="jdbc:postgresql://localhost:5432/product" \
--username=root \
--password=123qwe \
updateSQL
@baybatu
baybatu / SwitchAliasJenkinsfile
Last active Feb 4, 2019
Switch `products` Elasticsearch alias between index versions on Jenkinsfile. Switching happens from `products_v1` to `products_v2`
View SwitchAliasJenkinsfile
#!/usr/bin/env groovy
node {
stage('checkout') {
checkout scm
}
stage("Switch alias between index versions") {
String esHost = params.esHost //example: localhost:9200
String oldIndexVersion = params.oldIndexVersion //example: v1
String newIndexVersion = params.newIndexVersion //example: v2
@baybatu
baybatu / ReIndexJenkinsfile
Last active Feb 4, 2019
ReIndex Elasticsearch index from one to another on Jenkinsfile. Example transfer happens from `products_v1` to `products_v2` index
View ReIndexJenkinsfile
#!/usr/bin/env groovy
node {
stage('checkout') {
checkout scm
}
stage("Reindex") {
String esHost = params.esHost //example: localhost:9200
String oldIndexVersion = params.oldIndexVersion //example: v1
String newIndexVersion = params.newIndexVersion //example: v2
@baybatu
baybatu / analytic-functions.md
Last active Feb 3, 2019
SQL'de ROW_NUMBER, RANK ve DENSE_RANK farklarını anlatan güzel bir örnek
@baybatu
baybatu / PaginationThroughHttpHeadersResponseAdvice.java
Last active Jan 22, 2019
Managing pagination through HTTP headers on Spring Boot. `PageResponseAdvice` intercepts responses in `PageResponse` type and puts pagination related fields into HTTP response headers.
View PaginationThroughHttpHeadersResponseAdvice.java
@ControllerAdvice
public class PageResponseAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return PageResponse.class.isAssignableFrom(returnType.getParameterType());
}
@Override
public Object beforeBodyWrite(Object body,
You can’t perform that action at this time.