Kuby Block

Blog about programming, tech, society and more.

Posts

  • Manually to create LDAP authentication provider

    Have you ever want to create a custom login flow with composite of ldap and other authentication? But you relize that, LDAP almost use integrated with Spring security? And you would like to use it seperatedly, yes, me too and now I will share you the way I have used. 1. Use class DefaultSpringSecurityContextSource to create LDAP context source. It is a little weird that we will use DefaultSpring...

  • Optional Parameters in Programing

    Optional parameters is the way for using method without required full all parameters in definition of method. It will be useful when using method in different contexts. Java In Java, we have two kinds of optional parameter of method: Overload methods Rest parameters Java: Overload methods In three methods below, we have different parameters for each method with the same method name: imp...

  • Be careful when using Scanner in Java

    To interact with a java application in command line, Scanner is one of the most popular way to implement. But you know, it also has a mistake that we may easily make. First, let use it in a simple program: import java.util.Scanner; public class Main { private static String inputString() { final Scanner scanner = new Scanner(System.in); String result = ""; if (scanner.hasNextLine...

  • Overload in JavaScript

    Overload is an interesting feature, with the same method name, we can use it in different cases. As a previous post, I have told about overloading vs overiding in OOP. But in JavaScript, overload does not exist. Simple case: function fn(x) { console.log("function with one parameter"); } function fn(x, y) { console.log("function with two parameters"); } Invoke it: fn(1); // Output: functi...

  • Call function with the specified parameter number

    In javascript, there are some situation we only want to call a function with one, two or three parameter(s), but input of it maybe there are a lot of parameters. For example, we want to repeat every element in array one time: const data = [2, 11, 6, 10]; // expected [22, 1111, 66, 1010] What will you do? Simplest, we can do: const data = [2, 11, 6, 10]; data.map(el => el.toString()).ma...

subscribe via RSS