No New New: Raw Pointers Removed from C++

Two weeks ago, the ISO C++ standard meeting took place in Jacksonville. Today I want to make a short detour and write about the revolutionary decision that was made in the Jacksonville meeting. Additionally, I refer to the Will no Longer Have Pointers by Fluent C++. The standard committee decided that pointers will be deprecated in C++20 and will with very high probability removed in C++23.

To be honest, what seems like a revolution is only the last step in a long evolution. First, let me explain the big picture.

 The evolution of pointers in C++

Pointers are part of C++ since the first beginning. We got them from C. From the first beginning there was always the tendency in C++ to make the handling with pointers more type-safe without paying the extra cost.

With C++98 we got std::auto_ptr to express exclusive ownership. But std::auto_ptr had a big issue. When you copy an std::auto_ptr the resource will be moved. What looks like a copy operation was actually a move operation. The graphic shows the surprising behaviour of an std::auto_ptr.

This was extremely bad and the reason for a lot of serious bugs; therefore, we got std::unique_ptr with C++11 and std::auto_ptr was deprecated in C++11 and finally removed in C++17. Additionally, we got std::shared_ptr and std::weak_ptr in C++11 for handling shared ownership. You can not copy but move an std::unique_ptr and if you copy or assign an std::shared_ptr, the internal reference counter will be increased. Have a look here:

Since C++11 C++ has a multithreading library. This makes the handling with std::shared_ptr quite challenging because an std::shared_ptr is per definition shared but not thread-safe. Only the control-block is thread-safe but not the access to its resource. That means, modifying the reference counter is an atomic operation and you have the guarantee that the resource will be deleted exactly once. This is the reason we will get with C++20 atomic smart pointers: std::atomic_shared_ptr and std::atmic_weak_ptr. Read the details in the proposal: Atomic Smart Pointers.

“A Guide to Becoming a Full-Stack Developer in 2017”

Being a Full-Stack Developer doesn’t mean that you have necessarily mastered everything required to work with the front-end or back-end, but it means that you are able to work on both sides and understand what is going on when building an application.

Full-Stack Web Development, according to the Stack Overflow 2016 Developer Survey, is the most popular developer occupation today. It’s no wonder then that there are dozens of online and in-person programs that will help people become Full-Stack Developers and then even assist these new developers land high-paying programming jobs.

Some popular online programs can be found on Lynda, Udacity, Coursera, Thinkful, General Assembly, and so much more. Aside from these online programs, there are also in-person coding bootcamps that are teaching people the skills required to become web developers.

In this article I won’t be discussing which websites or coding bootcamps have the best web development programs, instead I will be providing a definitive guide to what I believe are the most important skills required to become a Full-Stack Web Developer today and land a job if you’ve never coded before. I will be basing the list off of three things:

  1. A combination of what most programs in 2017 are teaching students.
  2. My own personal experiences from interviewing at companies for developer positions in the past and also interviewing potential candidates for current Full-Stack Developer positions at my current company.
  3. Stories and feedback from people on Coderbyte who have been accepted to coding bootcamps and then proceeded to get programming jobs (see below).

 

“A Guide to Becoming a Full-Stack Developer in 2017” @borowskidaniel https://medium.com/coderbyte/a-guide-to-becoming-a-full-stack-developer-in-2017-5c3c08a1600c

Code Like a Pythonista: Idiomatic Python

Dictionary and Iterators

Dictionaries implement a sq_contains slot that implements the same test as the has_key() method. This means that we can write

Dictionaries implement a tp_iter slot that returns an efficient iterator that iterates over the keys of the dictionary. During such an iteration, the dictionary should not be modified, except that setting the value for an existing key is allowed (deletions or additions are not, nor is the update() method). This means that we can write

which is equivalent to, but much faster than

as long as the restriction on modifications to the dictionary (either by the loop or by another thread) are not violated.

Add methods to dictionaries that return different kinds of iterators explicitly:

This means that for x in dict is shorthand for for x in dict.iterkeys().

Other mappings, if they support iterators at all, should also iterate over the keys. However, this should not be taken as an absolute rule; specific applications may have different requirements.

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.

Source: http://www.omahapython.org/IdiomaticPython.html

The best code editors for WordPress developers

Hello! Since you are reading this article, it means that you are a WordPress developer, just like me, and strive to make your work with WordPress as productive as possible.

What do we have to do when creating sites on WordPress? We do not just edit PHP files. We should be a programmer and WEB-designer, have the skills to work with HTML, CSS and JavaScript, as it is necessary for a successful WEB-programming.

And a modern IDE or text editor that wants to win the favor of users should provide support for all the necessary languages and technologies.

As a rule, to manage several projects you need a full PHP development environment, such as PhpStorm or CodeLobster. But I also use text editors too, for example if I need to quickly correct a template or modify the code of my function.

Creators of code editors are constantly working on adding new and expanding existing capabilities of their products to support CMS WordPress. Because the community of programmers understand the importance of implementing WordPress support in their software.

I had to spend a lot of time to pick up several IDEs and text editors with advanced features and convenient functionality for WordPress developers.

I suggest you to discover these wonderful programs.

SublimeText

Sublime Text is a fast text editor with a fashionable user interface. It perfectly supports HTML, CSS and JavaScript syntax without additional plug-ins.

To expand the functionality and add tools for WordPress developers, you need to install special packages.

Run the program and go to the main menu “Tools” -> “Install Package Control …”. Package Control is a package that allows you to manage other plug-ins.

After that, you can download, install and remove plug-ins. To start the Package Control, go to the main menu “Preferences” -> “Package Control”.

In order for the program to load the list of available modules, it is necessary to select from the list or enter from the keyboard the command “Install Package”.

Let’s enter “WordPress” in the search bar to filter out the plug-ins specific to this CMS.

From the list, you can immediately select the first “WordPress” package and install it by double-clicking it. This package adds a set of snippets and the ability to auto-complete the functions of WordPress.

Sublime Text

The next plugin we select from the list is called “Search WordPress Codex”. Using it, you can search the official WordPress online help directly from the editor.

For example, right-click on the function and select “WordPress Codex” -> “Search Selection” from the context menu to view online help on it.

Sublime Text

Also there are several popular extensions that you should pay attention to, for example:

  • WordPress snippets – provides a collection of snippets for WordPress programmers.
  • WordPress New Project Config – helps you to create and configure a new project for WordPress CMS.
  • Genesis – facilitates the work of the creators of themes for WordPress, which use the child themes of Genesis.

Atom

Atom is another text editor with a lot of advanced functions and beautiful design. It positions itself as an IDE and successfully competes with other similar programs, such as Sublim Text and Rapid PHP.

Atom is based on themes and packages, so it has a wide range of functions and is flexibly configured. It has its own package manager, which we will use to install WordPress support.

Launch Atom and go to the main menu “File” -> “Settings”. In the opened settings tab, click on “Install”.

Now, to find new packages, enter the keyword “wordpress” in the search field and press “Enter”. You can also click on the “Packages” button.

In the list that appears, let’s choose one of the popular packages, for example – Autocomplete WordPress Hooks. This extension will help the developer by providing the completion of WordPress Actions and Filters.

Find this package in the list and click the “Install” button. After a minute we will see that the package is installed.

Now check the functionality of the just added module. Start type the name of the function and press Ctrl + Space.

Atom Now check the functionality of the just added module. Start type the name of the function and press Ctrl + Space.
Atom

After that, we can also use the hints on the parameters of the function.

Atom

The algorithm for working with other packages is the same. Just read the description, and if the functionality is suitable, install it.

For example, you can install the following add-ons:

  • WordPress API – this add-on greatly speeds up the development process, offering useful WordPress snippets.
  • WordPress Dictionary for Atom – adds snippets for all WordPress functions, including Actions and Filters.

Rapid PHP

Rapid PHP is also a good editor with support of PHP, HTML, CSS and JavaScript. It successfully combines the functionality of the real IDE with high speed.

It is not resource-demanding, has a built-in PHP debugger, supports HTML5, CSS3 and several frameworks, including WordPress.

For higher performance, ability to work with frameworks is disabled by default. To enable WordPress support, go to the main menu “Options” -> “Frameworks”.

In the list that appears, you can select one or more libraries that you want to work with. In this case, choose WordPress and click “OK”.

In the next step, let’s create the project, for that we go to the main menu and select “Project” -> “New Project”.

Now enter the project name and path to the project files. In this example, specify the folder with WordPress installed.

When the project is created, you can view its contents in the right pane of the program using the file browser.

Rapid PHP provides the programmer with ability to use the autocompletion feature when pressing the Ctrl + Space keys.

Rapid PHP
Rapid PHP

You can also trigger an instant prompt on WordPress functions by pressing Shift + Ctrl + Space.

Rapid PHP
Rapid PHP

If in the process of work you need to use the online help for any PHP function, just place the cursor on its name and press the F1 key. The page with online help will be displayed in the browser installed on the system.

CodeLobster

CodeLobster is a functional IDE that provides a complete set of tools for the web developer.

It has an editor of PHP, HTML, CSS and JavaScript with suggestions and autocompletion.

CodeLobster allows you to work with databases directly from the IDE, edit PHP files on the local computer and on a remote server using FTP.

Among other things, you can use PHP debugger, contextual and dynamic help.

There is a convenient function of installing WordPress directly from the program. In addition to that the CMS is installed and configured instantly, much faster than via the WEB-interface.

For example, to create a project, go to the main menu “Project” -> “Create Project …”.

Then in the dialog box, you can specify the type of the project, which will be created using the framework or one of the popular CMS.

Select “Create Empty WordPress Site”, enter the name and specify the location of the directory for installation. Then the New WordPress Site Wizard will run.

It will take only a few steps to configure the connection to the database and at the last step specify the parameters of our blog.

After clicking the “Finish” button, the fresh WordPress distribution will be installed and a new project will be created, you can immediately start working.

If we move the mouse pointer to any function name, we get information about it in a tooltip.

CodeLobster

For full information about this function from the official WordPress documentation, it is enough to select it and press the F1 key.

To use autocompletion, just start typing the name of the function and press Ctrl + Space.

CodeLobster

CodeLobster includes the WordPress plugin in its professional version. That allows the developer to quickly start working with this CMS, since no additional installation is required.

PhpStorm

PhpStorm is a PHP IDE with many convenient features for the web developer. This programming environment is built on the IntelliJ IDEA platform and inherited all the capabilities of the parent platform.

For WordPress programmers, the distribution of the IDE comes with a special plug-in for integration with WordPress.

To start working, you need to register WordPress in the program. Start PhpStorm and go to the main menu “File” -> “Settings …”.

In the settings we will find the section “Languages & Frameworks” and select the “PHP” item. Then in the “Include Path” tab we press the plus button and specify the path to the installed CMS.

The directory with the installation will be indexed, this will allow us to use the WordPress source code when navigating through functions and showing dynamic help.

In addition, you can set the WordPress coding style, which for sure has already became familiar to WordPress developers.

In the program settings window, go to “Editor” -> “Code Style” -> “PHP”. Click on the link “Set from …” and select “Predefined Style” -> “WordPress” from the drop-down list.

Click “OK” to save the settings.

Now consider the process of creation of a new project. In the main menu, select “File” -> “New Project …”.

In the opened dialog, go to the “WordPress Plugin” section and specify the directory for the project and the second one – there the WordPress is installed.

Choose the location of the project in the folder with WordPress. Then click “Create” – so we create a project based on the existing source files.

You should wait a few seconds while PhpStorm scans the files. After that the project is opened and we can continue to study the functions of the program.

To use auto-completion, start entering the name of the function and press Ctrl + Space.

PhpStorm

It is enough just to set the cursor to the function name and press Ctrl + Q to get dynamic help on this function.

PhpStorm

IDE also supports WordPress Actions and Filters. When you press Ctrl + Space, you can quickly get a dynamic hint about the existing parameters.

This review can be completed for now. As you can see, all of the programs in this article have their advantages.

Which one to choose? A simple and lightweight text editor, such as Rapid PHP, or a complex IDE, such as PhpStorm?

I chose CodeLobster, that combines the speed of work, functionality and ease of setting up WordPress projects. I’m happy to add it to my set of web development tools.

It’s very interesting to know what your favorite editor is? Do you create sites on WordPress, or use another CMS? I suggest sharing your experience with other readers. I really look forward to your comments.

 

Java wariacje z ciągiem Fibonacciego

Zadanie

Utwórz rekurencyjna metode obliczajaca ciag Fibonacciego, zdefiniowany dla elementu fibonacci(n) jako sume fibonacci(n-1) + fibonacci(n-2) przy załozeniu, ze fibonacci(1) i fibonacci(2) maja odpowiednio wartosci 1 i 2.

Ciąg Fibonaciego

In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones:[1][2]

1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , …

Often, especially in modern usage, the sequence is extended by one more initial term:

0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 , …[3]

The Fibonacci spiral: an approximation of the golden spiral created by drawing circular arcs connecting the opposite corners of squares in the Fibonacci tiling;[4] this one uses squares of sizes 1, 1, 2, 3, 5, 8, 13, 21, and 34.

By definition, the first two numbers in the Fibonacci sequence are either 1 and 1, or 0 and 1, depending on the chosen starting point of the sequence, and each subsequent number is the sum of the previous two.

In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation

{\displaystyle F_{n}=F_{n-1}+F_{n-2},}

with seed values[1][2]

  {\displaystyle F_{1}=1,\;F_{2}=1}

or[5]

{\displaystyle F_{0}=0,\;F_{1}=1.}

The Fibonacci sequence is named after Italian mathematician Leonardo of Pisa, known as Fibonacci. His 1202 book Liber Abaci introduced the sequence to Western European mathematics,[6] although the sequence had been described earlier as Virahanka numbers in Indian mathematics.[7][8][9] The sequence described in Liber Abaci began with F1 = 1.

Fibonacci numbers are closely related to Lucas numbers  L_{n} in that they form a complementary pair of Lucas sequencesU_{n}(1,-1)=F_{n} and V_{n}(1,-1)=L_{n}. They are intimately connected with the golden ratio; for example, the closest rational approximations to the ratio are 2/1, 3/2, 5/3, 8/5, … .

Fibonacci numbers appear unexpectedly often in mathematics, so much so that there is an entire journal dedicated to their study, the Fibonacci Quarterly. Applications of Fibonacci numbers include computer algorithms such as the Fibonacci search technique and the Fibonacci heap data structure, and graphs called Fibonacci cubes used for interconnecting parallel and distributed systems. They also appear in biological settings,[10] such as branching in trees, phyllotaxis (the arrangement of leaves on a stem), the fruit sprouts of a pineapple,[11] the flowering of an artichoke, an uncurling fern and the arrangement of a pine cone‘s bracts.[12]

— Source: https://en.wikipedia.org/wiki/Fibonacci_number

Closed form

\(x_{n}=\frac{(1+5^{1/2})^{n} -(1-5^{1/2})^n}{\sqrt{5}2^n}\)

https://math.stackexchange.com/questions/1145342/find-a-formula-for-the-nth-fibonacci-number?newreg=1b687d38e42346fa97a2fdfe3a94c389

Java program and others interesting links

Sources from Bitbucket

bitbucket-icon

 

 

/*
 * Example program to find fibonacci numbers
 */
package Fibonacci;

import static java.lang.Math.sqrt;
import java.util.Scanner;

/**
 *
 * @author KPreiskorn
 */
public class Fibonacci {

  /**
   * @param args the command line arguments
   */
  @SuppressWarnings("resource")
  public static void main(String args[]) {

    // input to print Fibonacci series upto how many numbers
    log("Enter number n Fibonacci to print: ");
    int number = new Scanner(System.in).nextInt();

    log("\nUsing Method-1: Using Recursion. Provided Number: " + number);
    // printing Fibonacci series upto number
    for (int i = 1; i <= number; i++) {
      System.out.printf("%3d %6d\n", i, fibonacciRecusion(i));
    }

    log("\nMethod-2: Fibonacci number at location " + number + " is ==> " + (fibonacciLoop(number) + ""));

    System.out.printf("\nMethod #3 (fibonacciClosedForm): Fibonacci number at location %d is %.0f\n\n", number, fibonacciClosedForm(number));

  }

  // Method-1: Java program for Fibonacci number using recursion.
  public static int fibonacciRecusion(int number) {
    if (number == 1 || number == 2) {
      return 1;
    }

    return fibonacciRecusion(number - 1) + fibonacciRecusion(number - 2); // tail recursion
  }

  // Method-2: Java program for Fibonacci number using Loop.
  public static int fibonacciLoop(int number) {
    if (number == 1 || number == 2) {
      return 1;
    }
    int fibo1 = 1, fibo2 = 1, fibonacci = 1;
    for (int i = 3; i <= number; i++) {
      fibonacci = fibo1 + fibo2; // Fibonacci number is sum of previous two Fibonacci number
      fibo1 = fibo2;
      fibo2 = fibonacci;

    }
    return fibonacci; // Fibonacci number
  }

  // metod 3: Closed-form expression
  public static double fibonacciClosedForm(int n) {
    double q = (1 + sqrt(5)) / 2;

    return Math.floor(Math.pow(q, n) / sqrt(5) + 1 / 2); // Fibonacci number
  }

  private static void log(String number) {
    System.out.println(number);

  }

}

What are the best programming fonts?

The choice the font in Firefox or Sulbimetext it is always hard decision….

As much as choice of a font is subjective there are important criteria to consider when choosing a programming font. The characters should be clear, easy to read, in cases of clashing ones such as 1, l, i or O, o, 0 easily distinguishable, differences between different kinds of brackets, quotes and parentheses should be clear, punctuation should be emphasized and they shouldn’t break up words or sentences due to uneven character widths. There are two ways fonts are drawn – as bitmaps or as vectors. Vector fonts allow more efficient scaling, but for screens with resolution below 720p it might be worth considering bitmap fonts as they are generally more legible at smaller sizes on low-resolution screens.

Source: What are the best programming fonts? – Slant

Java – Suma kolejnych liczb całkowitych od 5 do 1000

Zadanie 1. Suma kolejnych liczb całkowitych od 5 do 1000

Sumowanie – operacja dodawania ciągu liczb, której wynikiem jest suma. Jeśli liczby są dodawane kolejno od lewej do prawej to pośrednie wyniki nazywa się sumami częściowymi lub cząstkowymi. Sumowane liczby (zwane składnikami) mogą być całkowite, rzeczywiste lub zespolone. Oprócz liczb sumowaniu mogą podlegać również inne wielkości: wektory, macierze, wielomiany, lub ogólnie, elementy grupy addytywnej (a nawet monoid). Dla ciągów o skończonej liczbie takich elementów sumowanie zawsze zwraca dobrze określoną sumę.

Sumowanie ciągów nieskończonych nie zawsze jest możliwe, a kiedy wartość nieskończonego sumowania może być podana, to obejmuje ona więcej niż tylko zwykłą operację dodawania, mianowicie pojęcie granicy. Sumowanie nieskończonych ciągów tworzy konstrukcję zwaną szeregiem. Innym pojęciem obejmującym granice skończonych sum jest całka. Pojęcie sumowania nabiera szczególnego znaczenia w powiązaniu z ekstrapolacją w kontekście szeregów rozbieżnych.

Sumowanie ciągu [1, 2, 4, 2] to wyrażenie, którego wartością jest suma wszystkich elementów ciągu. W podanym przykładzie to 1 + 2 + 4 + 2 = 9. Ponieważ dodawanie jest łączne, wynik nie zależy od kolejności wykonywanych działań, na przykład (1 + 2) + (4 + 2) lub 1 + ((2 + 4) + 2) daje w wyniku 9, stąd zazwyczaj pomijane są nawiasy w przypadku wielokrotnego dodawania. Dodawanie jest ponadto przemienne, więc permutacja wyrazów skończonego ciągu również nie zmienia jego sumy (w przypadku ciągów nieskończonych ta właściwość nie zawsze jest prawdziwa; zobacz twierdzenie Riemanna o szeregach warunkowo zbieżnych i kryteria zbieżności szeregów).

Nie ma specjalnego wyróżnionego zapisu sumowania jawnie podanych ciągów gdyż odpowiadające mu wyrażenie wielokrotnego dodawania jest w tym przypadku wystarczające. Drobne trudności pojawiają się gdy ciąg jest jednoelementowy: sumowanie ciągu jednoelementowego nie zawiera znaku dodawania (jest więc nieodróżnialne od wyniku) a sumowanie ciągu pustego nie da się nawet zapisać (lecz można podać w jego sumę „0”). Jednak gdy wyrazy ciągu układają się w jakiś wzór to użyteczny a nawet niezbędny staje się operator sumowania. Na przykład jeśli rozpatrywać sumowanie liczb całkowitych od 1 do 100 można wykorzystać wielokropek w wyrażeniu dodawania aby oznaczyć brakujące wyrazy: 1 + 2 + 3 + … + 99 + 100. W tym przykładzie wzór jest łatwy do odgadnięcia, lecz dla bardziej skomplikowanych przypadków konieczne jest bardziej precyzyjne określanie kolejnych wyrazów, które można osiągnąć dzięki operatorowi „Σ”. Korzystając z tego operatora ten sam przykład można zapisać jako:

  \sum _{{i=1}}^{{100}}i

Wartością tego sumowania jest 5050. Można ją znaleźć bez wykonywania 99 dodawań, ponieważ można wykazać (metodą indukcji matematycznej), że

  \sum _{{i=1}}^{n}i={\frac {n(n+1)}2}

dla wszystkich liczb naturalnych n.

— źródło Wiki https://pl.wikipedia.org/wiki/Sumowanie

Zadanie 2. Utwórz tablice 5-cio elementową i wygeneruj do niej losowe wartości z przedziału <-10, 10>

Zadanie 3. Oblicza ile jest dodatnich elementów w tablicy myIntArray.

np. odpowiedź programu: W tablicy myIntArray[5] jest/są  3 dodatnie elementy

Source from Bitbucket https://bitbucket.org/karol-preiskorn/java-examples/overview

/**
 *
 * SumN - java examples
 * 
 * 2017.11.26 new bitbucket repository 
 *
 */
package sum_natural;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.nio.charset.StandardCharsets;

/*
 * https://slf4j.org/manual.html
 */
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * main class
 * 
 * @ver 2017-11-27 poprawki nazw pakietów
 * 
 * 
 */
public class Sum_natural {
  
  /**
   * @param args
   *          the command line arguments
   */
  static Logger logger = LoggerFactory.getLogger("SumN");
  
  public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
    
    logger.info("start");
    
    // TODO code application logic here
    
    int suma; //
    int rn;
    int dodatnie;
    dodatnie = 0;
    suma = 0;
    
    int firstArg = 0;
    if (args.length > 0) {
      try {
        firstArg = Integer.parseInt(args[0]);
        
        if (firstArg < 5) {
          System.err.println("Argument" + args[0] + " musi być większy od zera.");
          System.exit(1);
        }
      } catch (NumberFormatException e) {
        System.err.println("Argument" + args[0] + " must be an integer.");
        logger.error("Argument" + args[0] + " must be an integer.");
        System.exit(1);
      }
      
      for (int i = 5; i <= firstArg; i++) {
        suma += i;
      }
      logger.info("Z1P1: Suma kolejnych liczb całkowitych od 5 do " + args[0] + " wynosi " + suma);
    } else {
      
      for (int i = 5; i <= 1000; i++) {
        suma += i;
      }
      logger.info("Z1P1: Suma kolejnych liczb całkowitych od 5 do 1000 jest równa: " + suma);
    }
    
    logger.info("Z1P2: Utwórz tablice n elemntów i wygeneruj do niej wartości z przedziału <-10, 10>");
    
    // deklaracja tablicy
    int[] myIntArray = new int[10];
    
    String v_array = "myIntArray[" + myIntArray.length + "] = { ";
    
    for (int i = 0; i < myIntArray.length; i++) {
      rn = -10 + (int) (Math.random() * 20);
      myIntArray[i] = rn;
      v_array += rn;
      if (i < myIntArray.length - 1) {
        v_array += ", ";
      }
    }
    
    v_array += " }";
    logger.info(v_array);
    
    logger.info("Z1P3: Oblicza ile jest dodatnich elementów w tablicy myIntArray[" + myIntArray.length + "]");
    
    for (int i = 0; i < 10; i++) {
      
      if (myIntArray[i] > 0) {
        dodatnie++;
      }
    }
    
    logger.info("W tablicy myIntArray[" + myIntArray.length + "] jest/sa  " + dodatnie + " dodatnie elementy");
    
    /*
     * @var http://stackoverflow.com/questions/2885173/how-to-create-a-file-and-write-to- a-file-in-java#2885224
     */
    
    try (PrintWriter writer = new PrintWriter("dodatnie.txt", "UTF-8")) {
      writer.println("W tablicy myIntArray[" + myIntArray.length + "] sa " + dodatnie + " dodatnie elementy.");
      writer.close();
      
    } catch (IOException e) {
    }
    
    try (Writer writer = new BufferedWriter(
        new OutputStreamWriter(new FileOutputStream("dodatnie2.txt"), StandardCharsets.UTF_8))) {
      writer.write("W tablicy myIntArray[" + myIntArray.length + "] sa  " + dodatnie + " dodatnie elementy");
    } catch (IOException ex) {
      // handle me
    }
    
    /*
     * Suma kwadratów n pierwszych liczb naturalnych (w przygotowaniu)
     * 1^{2}+2^{2}+3^{2}+4^{2}+\dots+n^{2}=\sum_{k=1}^{n}k^{2}=\frac{n(n+1)(2n+1)}{6}=s_{2}
     */
    int n = 100;
    
    logger.info("Suma kwartat�w liczn naturalnych od 1 do n = " + n + " frac{n(n+1)(2n+1)}{6} = "
        + (n * (n + 1) * (2 * n + 1) / 6));
    
    logger.info("END");
  }
  
}

Zapis wyników do pliku

    /*
     * @var http://stackoverflow.com/questions/2885173/how-to-create-a-file-and-write-to- a-file-in-java#2885224
     */
    
    try (PrintWriter writer = new PrintWriter("dodatnie.txt", "UTF-8")) {
      writer.println("W tablicy myIntArray[" + myIntArray.length + "] sa " + dodatnie + " dodatnie elementy.");
      writer.close();
      
    } catch (IOException e) {
    }
    
    try (Writer writer = new BufferedWriter(
        new OutputStreamWriter(new FileOutputStream("dodatnie2.txt"), StandardCharsets.UTF_8))) {
      writer.write("W tablicy myIntArray[" + myIntArray.length + "] sa  " + dodatnie + " dodatnie elementy");
    } catch (IOException ex) {
      // handle me
    }

Dodanie logowania log4j (w przygotowaniu)

uses log4j in code
static Logger logger = LoggerFactory.getLogger("SumN");	  

logger.info("start");
  1. https://alvinalexander.com/blog/post/java/sample-how-format-log4j-logging-logfile-output
  2. https://alvinalexander.com/blog/post/java/how-print-exception-stack-trace-using-log4j-commons
  3. https://logging.apache.org/log4j/1.2/manual.html

Suma kwadratów n pierwszych liczb naturalnych (w przygotowaniu)

\(1^{2}+2^{2}+3^{2}+4^{2}+\dots+n^{2}=\sum_{k=1}^{n}k^{2}=\frac{n(n+1)(2n+1)}{6}=s_{2}\)

https://pl.wikisource.org/wiki/Sumy

    /*
     * Suma kwadratów n pierwszych liczb naturalnych (w przygotowaniu)
     * 1^{2}+2^{2}+3^{2}+4^{2}+\dots+n^{2}=\sum_{k=1}^{n}k^{2}=\frac{n(n+1)(2n+1)}{6}=s_{2}
     */
    int n = 100;
    
    logger.info("Suma kwartat�w liczn naturalnych od 1 do n = " + n + " frac{n(n+1)(2n+1)}{6} = "
        + (n * (n + 1) * (2 * n + 1) / 6));
    
    logger.info("END");
  }
  

SublimeText 3 tips and customization

One of best text editor for Linux and W$ bellow some tips and usefully configuration

Regexp conversion to Wiki links

Conversion to Wiki links add [ before and ] after text.

Find what: (http.{2,})
Relpace to: [\1]

Polish letters

Polskie znaki diakrytyczne w Sublime Text 3 – dodanie wpisów do Key Bindings – User (na platformie Windows jest to plik Default (Windows).sublime-keymap):

Adding comma to each line using sublime text

To add comma to any line

  1. Select the lines you want to modify
  2. CTRL + SHIFT + L
  3. RIGHT_ARROW
  4. COMMA

Using ctrl + shift + L is how you can modify all selected lines. Very handy 🙂 Make batch edits with Multiple Selections.

Column Selection can be used to select a rectangular area of a file. Column selection doesn’t operate via a separate mode, instead it makes use of multiple selections.

You can use additive selections to select multiple blocks of text, or subtractive selections to remove a block.

‘Find What’: $ // matching all ends of your lines
‘Replace With’: , // replaces all line ends with a coma

Solve this problem

Links

  • https://www.shortcutfoo.com/blog/sublime-text-3-gifs-cheat-sheet/
  • https://forum.sublimetext.com/t/my-sublime-text-windows-cheat-sheet/8411

Source: Best of Sublime Text 3: Features, Plugins, and Settings | Scotch

Sublime Text 3 is an amazing piece of software. To start, it is a clean, functional, and fast code editor. Not only does it have incredible built in features (multi-edit and vim mode), but it has support for plugins, snippets, and many other things.

Source: Best of Sublime Text 3: Features, Plugins, and Settings | Scotch

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑