Skip to content

Instantly share code, notes, and snippets.

View dan-dm's full-sized avatar
📚
Learning

Dan Dumitrescu dan-dm

📚
Learning
View GitHub Profile
@dan-dm
dan-dm / chmod-400.cmd
Created March 28, 2021 00:22 — forked from jaskiratr/chmod-400.cmd
Set permission of file equivalent to chmod 400 on Windows.
# Source: https://stackoverflow.com/a/43317244
$path = ".\aws-ec2-key.pem"
# Reset to remove explict permissions
icacls.exe $path /reset
# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r
@dan-dm
dan-dm / CompareObjects.java
Last active May 18, 2020 23:54
Created with Copy to Gist
src/main/java/Item.java
import java.util.Objects;
public class Item {
private String identifier;
private String name;
public Item(String identifier, String name) {
@dan-dm
dan-dm / custom.equals.java
Last active May 18, 2020 09:03
Created with Copy to Gist
src/main/java/Song.java
public class Song {
private String artist;
private String name;
private int durationInSeconds;
public Song(String artist, String name, int durationInSeconds) {
this.artist = artist;
@dan-dm
dan-dm / file.java
Created May 16, 2020 23:03
Created with Copy to Gist
Solution for part05-Part05_01.OneMinute
src/main/java/ClockHand.java
public class ClockHand {
private int value;
private int limit;
public ClockHand(int limit) {
this.limit = limit;
@dan-dm
dan-dm / readingCsvFiles.java
Last active May 16, 2020 14:42
Created with Copy to Gist
try (Scanner scanner = new Scanner(Paths.get("records.txt"))) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String[] parts = line.split(",");
String name = parts[0];
int age = Integer.valueOf(parts[1]);
System.out.println("Name: " + name);
@dan-dm
dan-dm / fileSkipLineEmpty.java
Created May 16, 2020 14:40
Created with Copy to Gist
// we create a scanner for reading the file
try (Scanner scanner = new Scanner(Paths.get("henkilot.csv"))) {
// we read all the lines of the file
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
// if the line is blank we do nothing
if (line.isEmpty()) {
continue;
@dan-dm
dan-dm / addOneIntToArray.java
Last active May 16, 2020 14:28
Created with Copy to Gist
public static int[] addOneIntToArray(int[] initialArray , int newValue) {
int[] newArray = new int[initialArray.length + 1];
for (int index = 0; index < initialArray.length; index++) {
newArray[index] = initialArray[index];
}
newArray[newArray.length - 1] = newValue;
return newArray;
}
@dan-dm
dan-dm / IsItInTheFile.java
Last active May 16, 2020 14:12
Created with Copy to Gist
src/main/java/IsItInTheFile.java
import java.nio.file.Paths;
import java.util.Scanner;
public class IsItInTheFile {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
@dan-dm
dan-dm / java.time.LocalDateTime.java
Created May 15, 2020 22:22
Created with Copy to Gist
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Item {
private String name;
private LocalDateTime createdAt;
public Item(String name) {
this.name = name;
@dan-dm
dan-dm / file.java
Created March 22, 2020 21:30
Created with Copy to Gist
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("================================");
for(int i=0;i<3;i++)
{
String s1=sc.next();