Skip to content

Instantly share code, notes, and snippets.

Working from home

Batuhan Bayrakci baybatu

Working from home
View GitHub Profile
baybatu /
Created Jun 26, 2016
Limiting input number between minimum and maximum values range in Python
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 /
Last active Sep 21, 2020
Mockito deep stubs for nested objects
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NestedObject nestedObject;

example usage in a test method:

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 -index 1
bind policy patset CORS_origins_allowed -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 / 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) {, e);
var array = [1,2,3];
eventify(array, function(newArray) {
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 /
Last active Aug 13, 2020
Accessing static constant values from Thymeleaf templates.

From expercise project:

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

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.

baybatu /
Last active Jun 10, 2020
Get next execution date for Spring cron expressions

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

new"0 0/5 * * * *").next(new Date())
baybatu /
Last active Jun 9, 2020
RabbitMQ: mesajı geciktirerek tüketmek

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 / 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.