Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Batuhan Bayrakci baybatu

🏠
Working from home
View GitHub Profile
@baybatu
baybatu / limit-number.py
Created Jun 26, 2016
Limiting input number between minimum and maximum values range in Python
View limit-number.py
def limit(num, minimum=1, maximum=255):
"""Limits input 'num' between minimum and maximum values.
Default minimum value is 1 and maximum value is 255."""
return max(min(num, maximum), minimum)
@baybatu
baybatu / mockito-deep-stubs.md
Last active Sep 21, 2020
Mockito deep stubs for nested objects
View mockito-deep-stubs.md
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NestedObject nestedObject;

example usage in a test method:

when(nestedObject.getStatusInfo().getValue().getStatus()).thenReturn(1);
@baybatu
baybatu / netscaler-cors-policy.txt
Last active Sep 17, 2020
Netscaler CORS configuration policy for multiple domains with their subdomains
View netscaler-cors-policy.txt
add policy patset CORS_origins_allowed
bind policy patset CORS_origins_allowed .validdomain1.com -index 1
bind policy patset CORS_origins_allowed .validdomain2.com -index 2
add responder action CORS_deny_response respondwith q{"HTTP/1.0 401 Unauthorized CORS\r\n\r\n"} -bypassSafetyCheck YES
add responder policy CORS_origin_denied `!(HTTP.REQ.HEADER("Origin").EXISTS && HTTP.REQ.HEADER("Origin").TYPECAST_HTTP_URL_T.HOSTNAME.CONTAINS_ANY("CORS_origins_allowed"))` CORS_deny_response
@baybatu
baybatu / attach-listener-to-push-method.js
Last active Sep 17, 2020
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 / split-into-subarrays.js
Last active Sep 5, 2020
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 / access-static-constant-thymeleaf.md
Last active Aug 13, 2020
Accessing static constant values from Thymeleaf templates.
View access-static-constant-thymeleaf.md

From expercise project:

<td>
  <input class="form-control" type="text" name="inputValue"
          th:maxlength="${T(com.expercise.utils.Constants).MAX_TESTCASE_VALUE_LENGTH}" />
</td>
@baybatu
baybatu / maven-war-exclude-directory.md
Last active Jun 30, 2020
Excluding Directory From War Package In maven-war-plugin
View maven-war-exclude-directory.md

packagingExcludes configuration tag can be used to exclude certain files or directories from the war file. It is important to put '/' character at the end of the directory to be excluded. If there is no such '/' character, then the entry is interpreted as a regular file.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.3</version>
    <configuration>
@baybatu
baybatu / next-execution-date-for-spring-cron-expressions.md
Last active Jun 10, 2020
Get next execution date for Spring cron expressions
View next-execution-date-for-spring-cron-expressions.md

I usually use Groovy Console to run code below to get next execution date for Spring cron expressions.

new org.springframework.scheduling.support.CronSequenceGenerator("0 0/5 * * * *").next(new Date())
@baybatu
baybatu / rabbitmq-delay-message-consume.md
Last active Jun 9, 2020
RabbitMQ: mesajı geciktirerek tüketmek
View rabbitmq-delay-message-consume.md

RabbitMQ: Mesajı Geciktirerek Tüketmek

  • delay-exchange: Geciktirilecek mesajın bırakıldığı exchange.
  • delay-queue: delay-exchange'e bağlı. Herhangi bir tüketicisi olmamalı.
  • ana-exchange: Geciktirilmeden tüketilmek istenen mesajların bırakılabileceği exchange.
  • ana-queue: ana-exchange'e bağlı kuyruk. Tüketicisi var.

delay-queue şu parametrelerle oluşturulur:

  • x-dead-letter-exchange: -- boş
  • x-message-ttl: 3000 -- mesajın bekletileceği milisaniye
@baybatu
baybatu / get-domain-mapping-in-grails.groovy
Last active May 24, 2020
Getting mapping from domain class in Grails
View get-domain-mapping-in-grails.groovy
class Person {
Long id
String name
static mapping = {
table name: 'PERSON'
id column: 'PRS_ID'
name column: 'PRS_NAME'
}
}
You can’t perform that action at this time.