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

@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 / find-and-delete-files-by-name.sh
Last active August 21, 2016 07:55
Delete found files in "find" command
find . -name '*.pyc' -delete