Skip to content

Instantly share code, notes, and snippets.

View baybatu's full-sized avatar
🏠
Working from home

Batuhan Bayrakci baybatu

🏠
Working from home
View GitHub Profile
@baybatu
baybatu / properties-dosya-veri-turleri.md
Last active January 6, 2016 08:00
java .properties dosyalarından boolean okumak istersek dikkat etmeli. Özellikle Groovy gibi dinamik dillerde...

Java'da .properties dosyalarındaki satırlar String isim-değer ikilileri şeklinde okunur.

myconfig.value = false

dendiği zaman buradaki false değeri bir String'dir ve buna dikkat etmek gerekir.

Örneğin Grails'de (2.x) Config.groovy'de ek properties dosyaları tanımlamak için grails.config.locations listesi tanımlanabilir.

@baybatu
baybatu / groovy-generic-metod-hatasi.md
Last active January 14, 2016 07:46
Groovy Generic Metod Ayıklama Hatası

Groovy'de

// derleme hatası
<T> void execute(Request<T> request) {
  // kodlar
}

tarzı bir metot imzası ayıklama hatasına(parsing error) sebep olur.

@baybatu
baybatu / creditcard-parser.js
Last active January 26, 2016 07:44
Parses credit card number with 16 characters into groups including 4 characters.
/*
* Example usage: parseCreditCard('1234567890123456') -> [ '1234', '5678', '9012', '3456' ]
*/
function parseCreditCard(cardNumber) {
return cardNumber.match(/.{1,4}/g);
}
@baybatu
baybatu / hashmap-values-hashcode.md
Last active January 26, 2016 07:16
HashMap#values() çağrılarında hashCode metoduna dikkat!

HashMap#values() metodu üzerinden bir HashMap üzerindeki değerleri alabiliriz. Aldığımız bu değerlerin hash code'ları üzerinden bir hesaplamaya girişeceksek bu durumda values().hashCode() metodu beklediğimiz sonuçları dönmeyebilir. Şöyle ki, farklı HashMap nesnelerinde aynı anahtar-değer ikilileri (key-value pair) olsa dahi o HashMap nesneleri üzerinden yapılacak values().hashCode() çağrıları farklı sonuçlar üretir.

Map<String, String> map1 = new HashMap<String, String>();
map1.put("key1", "value1");
map1.put("key2", "value2");

Map<String, String> map2 = new HashMap<String, String>();
map2.put("key1", "value1");
map2.put("key2", "value2");
@baybatu
baybatu / couchbase-view-sayi-formati-arama.md
Last active January 27, 2016 22:37
Couchbase view'larındaki sayı formatındaki string alanlara göre arama sorunu ve çözümü

Couchbase view'larında arama yapılacak alan string türünde fakat arama sorgusu(key) sayı formatında ise bu durumda Couchbase'in 1.4.9'a kadar olan java client'ları bu key'i sayı formatında sorguya gönderir ve boş sonuç döner.

Örneğin şöyle bir Couchbase dokümanımız olsun:

{
	"isim": "Batuhan",
	"numara": "1234"
}
@baybatu
baybatu / split-into-subarrays.js
Last active March 11, 2021 03:47
Splitting array into list of subarrays in javascript
/*
* 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 / groovy-xml-without-whitespaces.groovy
Created February 7, 2016 17:11
Write XML into a file without whitespace character in Groovy
import groovy.xml.MarkupBuilder
/**
* Produces xml file that has no whitespace character.
*
* new IndentPrinter(out, "", false) section does all things we need to do.
*
* Example output:
* <products><product><title>product title</title><price>100</price></product></products>
*
@baybatu
baybatu / plsql-upsert.sql
Last active April 27, 2016 12:58
Upsert example in PL/SQL
-- Insert entity into MY_TABLE table using 'entity_id' and 'name' fields if not exists.
-- Otherwise, update row's 'name' field.
MERGE INTO MY_TABLE TBL USING dual ON (TBL.entity_id = ?)
WHEN NOT MATCHED THEN INSERT (entitiy_id, name) VALUES (?, ?)
WHEN MATCHED THEN UPDATE SET TBL.name = ?
@baybatu
baybatu / optional-parentheses-uppercase-bug-groovy.groovy
Last active February 28, 2016 08:11
It is must to use parentheses while calling function or method that starts with an uppercase letter in Groovy 2.4.5
def foo(arg) {
println(arg)
}
def Bar(arg) {
println(arg)
}
foo "berbat"
foo("berbat")
@baybatu
baybatu / google-analytics-weblogic-key-not-found-problem.md
Last active March 2, 2016 19:33
Problem of private key file(.p12) not found while Google Analytics API authenticating in WebLogic

I encountered with a problem in WebLogic about to find full path of .p12(private key file) that needs to be specified for Google Analytics API authentication.

My private key file (google_analytics_private_key.p12) was in path '<PROJECT_PATH>/src/main/resources/keys/google_analytics_private_key.p12' in project source. Key loader method was such below and it worked in Tomcat flawlessly but not in WebLogic.

public String getGoogleAccountPrivateKeyFile() {
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL resource = loader.getResource("/keys/google_analytics_private_key.p12");
    return resource.getFile();
}