Skip to content

Instantly share code, notes, and snippets.

View Nikolay995's full-sized avatar

Nikolay Kondratenko Nikolay995

  • Ukraine, Kyiv
View GitHub Profile
@Nikolay995
Nikolay995 / BubbleSort.java
Last active March 22, 2018 16:06
Java Bubble Sort (using boolean variable)
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] mas = {2, 11, 4, 144, 32, 58, 1};
boolean isSorted = false;
while (!isSorted){
isSorted = true;
for (int i = 0; i <mas.length-1 ; i++) {
if (mas[i] > mas[i+1]){
@Nikolay995
Nikolay995 / Filter.java
Last active March 28, 2018 16:21
FileFilter implementation
import java.io.File;
import java.io.FileFilter;
/**
Класс, который реализует интерфейс FileFilter и используется для поиска файлов только с тем расширением,
которое передано его конструктору в качестве параметра
MyFilter filter = new MyFilter("doc");
@Nikolay995
Nikolay995 / CopyFile.java
Created March 28, 2018 16:40
FileInputStream/FileOutputStream Example
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyFile {
public static void main(String[] args) {
try (FileInputStream fis = new FileInputStream("a.txt");
FileOutputStream fos = new FileOutputStream("acopy.txt")) { //блок try c ресурсами
byte[] bufer = new byte[1024]; //буфферный массив
@Nikolay995
Nikolay995 / PrintfExample.java
Last active March 30, 2018 15:06
Java Printf Example
public class PrintfExample {
public static void main(String[] args) {
int a = 5;
String b = "five";
System.out.printf("A equals %d, and B equals %s", a , b);
}
}
@Nikolay995
Nikolay995 / RandArray.java
Last active March 30, 2018 15:08
Filling an Array With Random Numbers
import java.util.Random;
public class RandArray {
public static void main(String[] args) {
int[] array = new int[200_000_000];
Random rn = new Random();
for (int i = 0; i < array.length; i++) {
array[i] = rn.nextInt(10);
}
}
@Nikolay995
Nikolay995 / FindFactorial.java
Created April 2, 2018 16:08
The simplest factorial algorithm in Java
public class FindFactorial {
public static void main(String[] args) {
System.out.println(factorial(5));
}
private static int factorial(int x){
return (x == 1 ? 1 : x*factorial(x-1));
}
}
@Nikolay995
Nikolay995 / sublime-text-3-windows-shortcuts.md
Created April 16, 2018 14:00
Sublime Text 3 - Useful Shortcuts (Windows)

Sublime Text 3 - Useful Shortcuts (Windows)

General

Shortcut Description
Ctrl+Shift+P command prompt
Ctrl+Alt+P switch project
Ctrl+P go to file
Ctrl+G go to line
@Nikolay995
Nikolay995 / idea_cheatsheet.md
Last active April 16, 2018 14:02
Intellij IDEA - Cheat Sheet

Intellij IDEA - Cheat Sheet (aka my most used shortcuts)

Search/Replace

  • Double-press Shift - Search everywhere

Editing

  • Alt + J - Select the next occurrence (Sublime Text Style)
  • Shift + Ctrl + Alt + J - Select all occurrences
@Nikolay995
Nikolay995 / InetWork.java
Created April 16, 2018 16:56
Save content to file using URLConnection and byte buffers
public class InetWork {
public static void saveToFile(String address, File folder) {
try {
URL url = new URL(address); //установка соединения
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); //возможность доступа
InputStream is = connection.getInputStream(); //поток
int n = address.lastIndexOf("/"); //после последнего слеша будет имя файла
String fileName = address.substring(n + 1); //записываем сюда имя файла
File file = new File(folder, fileName); //сохраняем в каталоге фолдер с именем файлНейм
OutputStream os = new FileOutputStream(file);
@Nikolay995
Nikolay995 / git.md
Created April 16, 2018 16:58
Git commands

Git Commands

--

Getting & Creating Projects

Command Description
git init Initialize a local Git repository
git clone ssh://git@github.com/[username]/[repository-name].git Create a local copy of a remote repository