snippetjournal

– notes, snippet codes, and my journal

Cloud IDE

leave a comment »

Kata suhu suhu dikaskus lumayan lho bisa buat belajar ngoding di environment cloud dan VPS, untuk yang gratisan kekurangan nya VPS bisa aktif ketika kita sedang online saja 😀

Written by snippetjournal

September 22, 2016 at 3:16 am

Posted in Uncategorized

JPA Object Relations

leave a comment »

Written by snippetjournal

August 23, 2016 at 6:41 am

Posted in Uncategorized

Hot Swap In Spring boot

leave a comment »

Written by snippetjournal

May 27, 2016 at 9:45 am

Posted in Uncategorized

[Oracle] ORA-02292 : Mencari Table Constraints dengan Constraints Name

leave a comment »

mencoba mengupdate salah satu column pada row, tetapi terkena error seperti ini :

update auth_users set username = ‘user1@test.co.id’ where name = ‘user@test.co.id’
Error report –
SQL Error: ORA-02292: integrity constraint (ADMIN.FK_2TUB76GCBJC6VCSO1FBE15L3P) violated – child record found
02292. 00000 – “integrity constraint (%s.%s) violated – child record found”
*Cause: attempted to delete a parent key value that had a foreign
dependency.
*Action: delete dependencies first then parent or disable constraint.

 

maka kita dapat mencari tahu, constraints name itu milik table siapa (FK_2TUB76GCBJC6VCSO1FBE15L3P). gunakan syntax berikut :

select table_name from user_constraints where constraint_name=’FK_2TUB76GCBJC6VCSO1FBE15L3P’;

Written by snippetjournal

January 4, 2016 at 10:26 am

Posted in Programming

Tagged with ,

Immutability and Mutability

leave a comment »

Immutable
+ No thread locks
+ Fast read and lookup
– Bad for objects that highly mutable (increase memory usage every time it mutates)

Mutable
+ Fast for highly mutable objects
+ Low memory footprint
– Thread locks

Where you use immutable/mutable depending on the objects and pattern utilized. Functional and Math programming requires immutability on all objects to ensure consistency with parallel execution. Object Oriented apps rarely needs immutability since object is reused over and over with high mutability.

1 very clear example of mutability : Try playing games and imagine if all the objects is immutable, including interaction between objects (player on terrain, player vs player, gravity simulation, etc) and if this immutable, how do you deal with the number of objects generated every time it mutates.

1 example for immutability : Math calculation that can be break down and spread across multiple parallel threads (calculating/simulating)

http://www.kaskus.co.id/show_post/56611221dc06bd54638b4568/4041/-

Written by snippetjournal

December 4, 2015 at 7:47 am

Posted in Uncategorized

Back To Basic : SOLID, DRY and KISS

leave a comment »

S.O.L.I.D Principles

Single Responsibility 

  • One class should have one and only one responsibility.
  • This concept will give you the flexibility to make changes in the future without worrying the impact to another class.

 

Open Closed Principle

  • A class should be open for extension but closed for modification.
  • The “closed” part mean the module/class should only adjusted to correct bugs.
  • The “open” part mean fellow developer should be able to extend existing code in order to introduce new functionality.
  • Fellow developer should be able to override the options by software in un-harmful way permitted by software.

 

Liskov Substitution Principle

  • Liskovs Substitution Principle states that any method that takes class X as a parameter must be able to work with any subclasses of X.
  • Subtypes must be substitutable for their base types.
  • A subclass should override the parent class’ methods in a way that does not break functionality from a client’s point of view

 

Interface Segregation Principle 

  • A Client should never be forced to implement an interface that doesn’t user or clients shouldn’t be forced to depend on methods they do not use.
  • ISP states that interfaces that have become “fat” (like god classes) should be split into several interfaces. A large interface makes it harder to extend smaller parts of the system.

 

Dependency Inversion Principle

  • Entities must depend on abstraction not on concretion.
  • It states that the high level module must not depend on the low level module, but they should depend on abstraction.

 

D.R.Y (Don’t Repeat Yourself) Principles

  • Don’t write duplicate code.
  • Use abstraction to abstract common things in one place.
  • If you have block of code in more than two place consider making it separate method.
  • If you think fellow developer will need the same method in the future (depend in the context of business flow which you implement), consider making it as component or utility class.
  • If you use a hard-code value more than one time make them public final constant.
  • Duplication not for code, but functionality.

 

K.I.S.S (Keep It Stupid Simple or Keep It Simple, Stupid)

  • Meaningful and clear name (adjusted in functionality and business context).
  • Break down your problem into many small problems.
    Keep your method small.
  • Each method should only solve one little problem, not many use case.
    Don’t afraid refactor your code, over and over again (ps. If you still have time).
  • Don’t afraid to throw away code.

 

Sometimes you will find the principle collide each other and you also must considering the impact of your code in the system performance, you can do a mistakes but don’t break things.

 

Written by snippetjournal

November 26, 2015 at 3:16 am

Posted in Uncategorized

Instalasi SonarQube & Analisa dengan sonar runner

leave a comment »

Instalasi SonarQube 

download sonarqube pada link berikut, http://www.sonarqube.org/downloads/ (pada tutorial berikut saya menggunakan sonarqube versi 4.5.6)

extract, dan ubah atau tambahkan konfigurasi pada file : \sonarqube-4.5.6\conf\sonar.properties

konfigurasi standar sebenarnya sudah ada templatenya pada file sonar.properties, hanya tinggal disesuaikan dengan environment yang kita pakai.

konfigurasi user dan password database :

sonar.jdbc.username=root
sonar.jdbc.password=password

konfigurasi koneksi database, saya memakai MySQL :

sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true

dengan konfigurasi seperti diatas, sudah cukup untuk menjalankan sonarqube :

\sonar-runner-2.4\bin\sonar-runner.bat

Saya memakai windowz, maka saya gunakan file *.bat

jika instalasi sukses, maka dashboard dari sonarQube bisa diakses melalui localhost:9000, dan untuk user/password adalah admin/admin.

Langkah selanjutnya adalah melakukan instalasi plugin, plugin plugin ini nantinya dibutuhkan untuk analisa source code dengan sonar runner.

Login sebagai administrator, klik setting->update center (menu sebelah kiri) -> available plugin (tab kedua pada tab plugins).

Pada contoh saya hanya akan meng-install plugin java saja, kamu membutuhkan restart pada sonarQube, ctrl + c  kemudian jalan-kan ulang startSonar.bat

 

 Instalasi Sonar runner

Project saya sebenarnya menggunakan maven, karena ada pemisahan module pada project java saya, saya kesulitan melakukan konfigurasi pada maven, yang terjadi adalah sonar pada maven/pom.xml gagal melakukan indexing, analisa tidak akan terjadi.

Maka agar lebih mudah saya menggunakan sonar runner, kelebihan nya adalah kita tidak akan bergantung pada build tools dari suatu project, sonar runner akan melakukan crawling  pada project kita, dan mengsinkronkan dengan data pada sonarQube sehingga hasil analisa dapat kita lihat pada dashboard.

Konfigurasi

sama seperti konfigurasi sonar yang sudah ada template nya, sonar runner pun sama, tetapi dengan beberapa tambahan konfigurasi project path yang akan dianalisa.

konfigurasi standar

#—– Default SonarQube server
sonar.host.url=http://localhost:9000

#—– MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8

#—– Global database settings
sonar.jdbc.username=root
sonar.jdbc.password=password

konfigurasi project path

# required metadata
sonar.projectKey=sample-project
sonar.projectName=sample-project
sonar.projectVersion=1.0

# project path
sonar.sources=F:/asn/workspace/apps/src/main/java/
sonar.projectBaseDir=F:/asn/workspace/apps/src/main/java/

#The value of the property must be the key of the language.
sonar.language=java

Jalankan file sonar-runner.bat untuk menjalankan analisa, pastikan sonarQube sudah dalam keadaan UP atau aktif.

\sonar-runner-2.4\bin\sonar-runner.bat

sonarrunner-analysis

Keyword dari selesai proses analysis adalah ANALYSIS SUCCESSFUL, jika proses telah selesai kamu dapat melihat hasil nya pada dashboard.

 

referensi :

Written by snippetjournal

November 20, 2015 at 7:55 am

Posted in Uncategorized

Java Material : Conference, Seminar and Java Enthusiast you must stalk !

leave a comment »

Sebagai catatan, Java di indonesia di “musim trend Startup” indonesia seperti tidak terdeteksi atau seperti gerakan underground, sedangkan di US/Eropa mereka masih saja aktif dan teknologi java pun berjalan bersama sama dengan teknologi lain dan metode/konsep baru di bidang programming yang sedang trend.

Sebagai informasi kita bisa mengikuti web dan event dari pivotal, java zone, java one dan evangelist atau penggiat pengiat java di luar indonesia, mereka cukup aktif di twitter.

Written by snippetjournal

October 29, 2015 at 6:23 am

Posted in Programming

Tagged with

Spring security : @PreAuthorize cheat Sheet

leave a comment »

Written by snippetjournal

October 9, 2015 at 4:08 am

My GitHub Cheat Sheet

leave a comment »

  • Clone repository without history / shallow clone

git clone –depth 1 git://github.com/example-user/example-repo.git

note :

  • –depth <depth>,. create a shallow clone with a history truncated to the specified number of revisions.
  • The process will copy only the latest revision of everything in the repository
  • The above command clones only the current HEAD
  • Clone only one branch 
git clone -b mybranch --single-branch git://sub.domain.com/repo.git
  • Combine shallow clone and clone only one branch

 git clone –depth 1 -b test-branch –single-branch https://github.com/xxx/Test.git

tutorial how to rewrite github history using “rebase

ref :

Written by snippetjournal

September 30, 2015 at 6:15 am

Posted in Uncategorized