Posts

Annotations in Java

@Retention(RetentionPolicy.RUNTIME) -  byte-code a yazilir ve VM runtime zamani istifade ede bilir @Retention(RetentionPolicy.CLASS) - byte-code a yazilir, VM istifade ede bilmir @Retention(RetentionPolicy.SOURCE) - byte-code a yazilmir. Yalniz compile zamani istifade olunur

Frontdan gelen base64 file contenti mail de attachment kimi gondermek

String cnt = attachmentDto.getContent(); int index = cnt.indexOf(",") + 1; // cnt = cnt.replaceFirst("^data:image/[^;]*;base64,?", ""); cnt = cnt.substring(index); byte[] bytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(cnt); mimeMessageHelper.addAttachment(    attachmentDto.getName(),    new ByteArrayResource(bytes) ); 

React JS. esas meqamlar

props ve state haqqinda props bir componentden digerine data dashimaq uchun istifade olunur. state ise bir basha componente aid olan bir ozellikdir. state deyishdiyi zaman componentin render funksiyasi ishe dushur ve sehife yeniden generasiya olunur. bele bir veziyyet dushunek ki, Parent componentden child component e bir data gonderirik. bu data parentin statein de saxlanib.  <Child someData = {this.state.someData}> </Child> bu child component bu data ile her hansisa html generasiya eleyir. daha sonra parent componentin state datasi deyishir. burda bele bir hal yaranir ki, child a gonderilen data bir basha parent in datasindan asilidir. parentin datasi deyishdiyine gore child in da datasi deyishir ve yeniden render funksiyasi ishe dushur. method istifadesi addToCart = (product) => {    alert(product.productName + " added to cart!"); } <Button     onClick={() => this.addToCart(product)}     color="success">     <spa...

JWT - generate public and private key (YML example)

@SpringBootApplication public class AuthServerApplication implements CommandLineRunner { public static void main(String[] args) { SpringApplication.run(AuthServerApplication.class, args); } @Override public void run(String... args) throws Exception { KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("RSA"); keyGenerator.initialize(1024); KeyPair kp = keyGenerator.genKeyPair(); PublicKey publicKey = kp.getPublic(); PrivateKey privateKey = kp.getPrivate(); String encodedPublicKey = Base64.getEncoder().encodeToString(publicKey.getEncoded()); String encodedPrivateKey = Base64.getEncoder().encodeToString(privateKey.getEncoded()); System.out.println(convertToPublicKey(encodedPublicKey)); System.out.println(); System.out.println(convertToPrivateKey(encodedPrivateKey)); } private static String convertToPrivateKey(String key) {         StringBuilder result = new StringBuilder();         result.append(...

Apache Mail - for mail operation

 <dependency> <groupId> org.apache.commons </groupId> <artifactId> commons-email </artifactId> <version> 1.5 </version> </dependency> MimeMessageParser parser = new MimeMessageParser((MimeMessage) message).parse(); "parser" ile body ni hem html, hem de text/plain formatinda chekmek mumkundur.

Gmail, Mail.ru ve Yandex(mail) servislerinde folderler ve maillerin chekilmesinin sade mentiqi

Image
Mail.ru servisi uzerinden gelen folderler UI Language den asili olmayaraq hemishe bir dilde gelir. Lakin Gmail da bu mentiq bashqadir. UI language gore folderler hemin language de gele biler. Eger folderleri chekib bazaya yaziriqsa, aydindir ki, UI terefde dil deyishse, bizim servisimiz duzgun ishlemeyecek. Duzgun ishlemeyecek deyerken, eyni Folderler muxtelif dillerde bazamiza otura biler.  Nece hell etmeli ? IMAPFolder classi var, hansi ki, Folder classini extends edir. Bize gelen Folder classinin obyektini IMAPFolder classina cast eleye bilerik. Bu da bize bu ozellikleri verir ki, folder e aid olan attributelari cekek.  Attributelara \Inbox, \Sent, \Trash ve s gostermek olar. Bu attributelara esasen folderin eslinde hansi folder oldugunu teyin etmek olar.  Birinci if sertinde yazilan kodun izahi : Gmail da custom folder anlayishi olmadigina gore, bele bir kod yazmisham. Gmail da yalniz custom label anlayishi movcuddur. Label a ise mesaji move elemek olur. Bir nov her h...

compare two instants (month or other fields)

Duration duration = Duration.between(LocalDate.now().minusMonths(2).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(),Instant.now()); System.out.println(duration.toDays());

get file from message - JavaMail library

get bytes BASE64DecoderStream base64DecoderStream = (BASE64DecoderStream) obj; byte[] byteArray = IOUtils.toByteArray(base64DecoderStream); byte[] encodeBase64 = Base64.encodeBase64(byteArray); ========= return inputstream for download process Resource <= InputStreamResource return new InputStreamResource(part.getInputStream());

receiver mail from server - IMAP - Java

Ilk once bize host, port, username ve password lazimdir. Host ve port serverden asili olaraq deyishe biler. Hal-hazir ki, numune gmail uchundur. [ get file from message ]

Create cache with expire time

first use @EnableCaching annotation in your Main or configuration class import com.google.common.cache.CacheBuilder; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.concurrent.TimeUnit; @Configuration public class CachingConfig {     @Bean     public CacheManager cacheManager() {         return new ConcurrentMapCacheManager() {             @Override             protected Cache createConcurrentMapCache(String name) {                 return new ConcurrentMapCache(                         name, ...