Skip to content

Instantly share code, notes, and snippets.

Batuhan Bayrakci baybatu

Block or report user

Report or block baybatu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@baybatu
baybatu / creditcard-parser.js
Last active Jan 26, 2016
Parses credit card number with 16 characters into groups including 4 characters.
View creditcard-parser.js
/*
* Example usage: parseCreditCard('1234567890123456') -> [ '1234', '5678', '9012', '3456' ]
*/
function parseCreditCard(cardNumber) {
return cardNumber.match(/.{1,4}/g);
}
@baybatu
baybatu / couchbase-view-sayi-formati-arama.md
Last active Jan 27, 2016
Couchbase view'larındaki sayı formatındaki string alanlara göre arama sorunu ve çözümü
View couchbase-view-sayi-formati-arama.md

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 Feb 7, 2016
Write XML into a file without whitespace character in Groovy
View groovy-xml-without-whitespaces.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 Feb 28, 2016
It is must to use parentheses while calling function or method that starts with an uppercase letter in Groovy 2.4.5
View optional-parentheses-uppercase-bug-groovy.groovy
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 Mar 2, 2016
Problem of private key file(.p12) not found while Google Analytics API authenticating in WebLogic
View google-analytics-weblogic-key-not-found-problem.md

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 Mar 9, 2016
Running processes associated with each open port.
View netstat-port-process-relation.md

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 Apr 21, 2016
Why we must use wrapper type such as Long instead of primitive ones such as long for entity ID in Hibernate?
View hibernate-primitive-vs-wrapper-type-for-id.md

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 Apr 27, 2016
Upsert example in PL/SQL
View plsql-upsert.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 Mar 16, 2016
Listing .jar file content from command-line
@baybatu
baybatu / process-old-files-by-lastmodifieddates.groovy
Created Jun 1, 2016
Process files by their last modified dates in Groovy
View process-old-files-by-lastmodifieddates.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()
}
}
}
You can’t perform that action at this time.