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 / get-startup-and-build-version-metadata-in-grails.groovy
Created June 6, 2016 14:48
Getting system startup date and build version in Grails
/**
* Simple build metadata from system.
*
* To populate application version, just give following parameter while generation WAR package on grails CLI.
*
* $ grails "set-version 1.4" "clean" "war myproject.war"
*
* '1.4' is just an example for build version. If you want to auto generate it by your CI such as Jenkins, then
* create an environment variable and pass it to CLI command.
*
@baybatu
baybatu / safe-method-name-in-before-interceptor.groovy
Last active July 7, 2016 08:19
Using safe method names in 'beforeInterceptor' interceptor in Grails 2.x
class MyController {
/**
* Normally, String type method name in except part of beforeInterceptor is legal. For example:
*
* def beforeInterceptor = [action: this.&intercept, except: ['index', 'hede', 'hodo']]
*
* But this is not safe for future naming refactorings. Instead, using closure-maker
* ampersand operator(.&) before method name and then getting 'method' property to get
* method name as String is better for future safe changes.
@baybatu
baybatu / jaxb-cdata-without-escaping.md
Last active July 21, 2016 11:23
Add CDATA block into your XML output without escaping in JAXB
JAXBContext jaxbContext = JAXBContext.newInstance(MyClass.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.setProperty("com.sun.xml.internal.bind.characterEscapeHandler", new CharacterEscapeHandler() {
                @Override
                public void escape(char[] ac, int i, int j, boolean flag, Writer writer) throws IOException {
                    writer.write(ac, i, j);
                }
            });
@baybatu
baybatu / variable-value-key-of-map.md
Last active July 24, 2016 23:52
Using value of a variable as map key in Groovy

If you want to use a variable value as key of your map, then you should wrap your key with parenthesis. It makes key to be considered as expression instead of String literal.

String keyVar = "mykey"

def map0 = [keyVar : 12]
assert map0.keyVar == 12
assert !map0.mykey
@baybatu
baybatu / java-notserializable-comparator.md
Last active July 25, 2016 08:49
Java'da TreeMap'i serialize ederken alınan NotSerializableException ve çözümü

TreeMap, sıralamada kullanmak üzere bizden bir Comparator nesnesi ister ve bu Comparator nesnesini bir field üzerinde tutar. Eğer TreeMap nesnesine verilen bu Comparator nesnesi Serializable değilse serialization esnasında (cache'e yazma gibi) NotSerializableException alınır. Özellikle anonim sınıf üzerinden oluşturulan Comparator nesnelerine dikkat etmek gerekir.

Çözüm, Comparator sınıfını Serializable olarak işaretlemektir. Anonim olarak oluşturulan Comparator yerine top-level (ayrı sınıf) biçiminde Comparator oluşturup Serializable interface'i ile bu sınıfı Serializable olarak işaretleyebiliriz.

Kaynak: http://stackoverflow.com/questions/20978922/java-unable-to-serialize-a-objects-which-contain-treemaps-with-comparators

@baybatu
baybatu / sql-null-min.md
Last active August 19, 2016 06:21
PL/SQL'de MIN fonksiyonuyla null yerine bir değer dönmek
SELECT
  MIN(NVL(t.column, 0))
FROM TABLE t
WHERE t.OTHERTABLE_ID = 1234
      AND t.Condition = 1;

Eğer Condition koşulunu sağlayan herhangi bir satır bulunamazsa bu durumda MIN fonksiyonu null döner. Bunu engellemek için MIN'i NVL ile sarmak faydalı olabilir.

@baybatu
baybatu / find-and-delete-files-by-name.sh
Last active August 21, 2016 07:55
Delete found files in "find" command
find . -name '*.pyc' -delete
@baybatu
baybatu / remove-last-files-by-minute.sh
Created October 30, 2016 16:16
Remove files those created/modified in last 20 minutes
find . -cmin -20 -delete
@baybatu
baybatu / pkg_resources-DistributionNotFound-six.md
Created November 8, 2015 16:56
A Solution For 'pkg_resources.DistributionNotFound six' Problem

Today i have decided to write some unit test on JavaScript via Jasmine, but i encountered the following exception stack trace.

Traceback (most recent call last):
  File "/usr/local/bin/jasmine", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
    working_set.require(__requires__)
 File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
@baybatu
baybatu / git-branch-contains.md
Created January 30, 2017 20:09
Git command that let you know which branchs contains the specified commit
git branch --contains COMMIT_SHA1