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 / 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 / see-java-jar-file-content.md
Created Mar 16, 2016
Listing .jar file content from command-line
@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 / sql-null-min.md
Last active Aug 19, 2016
PL/SQL'de MIN fonksiyonuyla null yerine bir değer dönmek
View sql-null-min.md
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 Jul 24, 2016
Using value of a variable as map key in Groovy
View variable-value-key-of-map.md

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 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()
}
}
}
@baybatu
baybatu / grails-render-method-download-file-not-found-error.md
Last active Jun 6, 2016
Grails'de dosya sunarken alınan "dosya bulunamadı" hatası ve çözümü
View grails-render-method-download-file-not-found-error.md

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 Jun 6, 2016
Getting system startup date and build version in Grails
View get-startup-and-build-version-metadata-in-grails.groovy
/**
* 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 Jul 7, 2016
Using safe method names in 'beforeInterceptor' interceptor in Grails 2.x
View safe-method-name-in-before-interceptor.groovy
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 Aug 21, 2016
Delete found files in "find" command
View find-and-delete-files-by-name.sh
find . -name '*.pyc' -delete
You can’t perform that action at this time.