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 / 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 / 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 / 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();
}
@baybatu
baybatu / netstat-port-process-relation.md
Last active March 9, 2016 09:58
Running processes associated with each open port.

Shell command that gives running processes associated with each open port.

netstat -tulpn
@baybatu
baybatu / hibernate-primitive-vs-wrapper-type-for-id.md
Last active April 21, 2016 11:22
Why we must use wrapper type such as Long instead of primitive ones such as long for entity ID in Hibernate?

I ran into similar problem, where I was trying to save an object where his id was a primitive field (long), and at the time of create the object, the id was set to 0 by default, and Hibernate assumed I wanted to update the row with id = 0 (which obviously doesn't exist). My solution was change the id field to Long (wrapper), and that way, when I create a new instance the id is set to null, and Hibernate understands I am inserting a new element to the database. I hope it helps. Thanks.

Source: http://stackoverflow.com/a/30492460

@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 / see-java-jar-file-content.md
Created March 16, 2016 07:21
Listing .jar file content from command-line
jar tf my-jar-file.jar
@baybatu
baybatu / process-old-files-by-lastmodifieddates.groovy
Created June 1, 2016 12:25
Process files by their last modified dates in Groovy
// 'delete' is a process example
public void deleteOldFiles(File path) {
long startOfDay = new Date().clearTime().time
path.eachFile { file ->
if (file.lastModified() < startOfDay) {
file.delete()
}
}
}
@baybatu
baybatu / grails-render-method-download-file-not-found-error.md
Last active June 6, 2016 13:17
Grails'de dosya sunarken alınan "dosya bulunamadı" hatası ve çözümü

Grails'de render metoduna (1) adresindeki file ve fileName parametrelerini vererek kullanıcının istediğimiz dosyayı indirmesini sağlayabiliriz. Fakat eğer tarayıcı "dosya bulunamadı" hatası veriyorsa bu durumda Grails'deki Config.groovy dosyasında bulunan grails.mime.types listesini kontrol etmek gerekir. Eğer indirmek istediğimiz dosya türü için gerekli mime türü bu listede yoksa hata alırız. Örneğin zip dosyası indirtmek istiyorsak bu durumda listeye zip:'application/zip' kaydını girmek gerekir.

(1): http://docs.grails.org/2.4.4/ref/Controllers/render.html

Kaynak: http://mrhaki.blogspot.com.tr/2013/09/grails-goodness-render-binary-output.html