Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dad129c

Browse files
committed
Merge branch 'main' into feature/search
2 parents 03a9632 + 6e7b4dd commit dad129c

33 files changed

+539
-44
lines changed

‎CONTRIBUTING.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ contributors: contributor1, contributor2, your-github-username
194194

195195
> We want to make sure that original author and contributor(s) are credited for their work.
196196
197-
198197
### Adding a New Category
199198

200199
If your snippet doesn’t fit into any existing category, you can create a new one! Just make sure it’s unique and doesn’t overlap with others (e.g., don’t create separate categories for "Date" and "Time" when "Date and Time" works).
@@ -208,7 +207,6 @@ If your snippet doesn’t fit into any existing category, you can create a new o
208207

209208
- Follow the [Adding a New Snippet](#adding-a-new-snippet) instructions.
210209

211-
212210
Example structure:
213211

214212
```md

‎cspell-dict.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
quicksnip
22
slugified
33
slugifyed
4+
sublanguage
5+
fastapi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Bit Counting
3+
description: Counts the set bits in the binary representation of an integer
4+
author: Mcbencrafter
5+
tags: math,number,bits,bit-counting
6+
---
7+
8+
```java
9+
public static int countBits(int number) {
10+
int bits = 0;
11+
12+
while (number > 0) {
13+
bits += number & 1;
14+
number >>= 1;
15+
}
16+
17+
return bits;
18+
}
19+
20+
// Usage:
21+
int number = 5;
22+
System.out.println(countBits(5)); // 2 (101)
23+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Is Power Of Two
3+
description: Checks if a number is a power of two
4+
author: Mcbencrafter
5+
tags: math,number,bit,power-of-two
6+
---
7+
8+
```java
9+
public static boolean isPowerOfTwo(int number) {
10+
return (number > 0) && ((number & (number - 1)) == 0);
11+
}
12+
13+
// Usage:
14+
int number = 16;
15+
System.out.println(isPowerOfTwo(5)); // true (2^4)
16+
```

‎snippets/java/date-time/date-time-formatting-american.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Date time formatting american
2+
title: Date Time Formatting American
33
description: Formats a timestamp to a human-readable date-time string in the format "MM/dd/yyyy hh:mm:ss a"
44
author: Mcbencrafter
55
tags: date,time,date-time,formatting,american

‎snippets/java/date-time/date-time-formatting-european.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Date time formatting european
2+
title: Date Time Formatting European
33
description: Formats a timestamp to a human-readable date-time string in the format "dd.MM.yyyy HH:mm:ss"
44
author: Mcbencrafter
55
tags: date,time,date-time,formatting,european

‎snippets/java/date-time/duration-formatting-hours-minutes-seconds.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Duration formatting hours minutes seconds
2+
title: Duration Formatting Hours Minutes Seconds
33
description: Converts a given time duration to a human-readable string in the format "hh:mm(:ss)"
44
author: Mcbencrafter
55
tags: time,formatting,hours,minutes,seconds

‎snippets/java/date-time/duration-formatting-minutes-seconds.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Duration formatting minutes seconds
2+
title: Duration Formatting Minutes Seconds
33
description: Converts a given time duration to a human-readable string in the format "mm:ss"
44
author: Mcbencrafter
55
tags: time,formatting,minutes,seconds

‎snippets/java/math/checksum.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Checksum
3+
description: Calculates the checksum of an int
4+
author: Mcbencrafter
5+
tags: math,number,checksum
6+
---
7+
8+
```java
9+
public static int checksum(int number) {
10+
number = Math.abs(number);
11+
int sum = 0;
12+
13+
while (number != 0) {
14+
sum += number % 10;
15+
number /= 10;
16+
}
17+
18+
return sum;
19+
}
20+
21+
// Usage:
22+
int number = 12345;
23+
System.out.println(checksum(number)); // 15 = 1+2+3+4+5
24+
```

‎snippets/java/math/factorial.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Factorial
3+
description: Computes the factorial of a given number
4+
author: Mcbencrafter
5+
tags: math,number,factorial
6+
---
7+
8+
```java
9+
import java.math.BigInteger;
10+
11+
public static BigInteger factorial(int number) {
12+
BigInteger result = BigInteger.ONE;
13+
14+
for (int currentNumber = 1; currentNumber <= number; currentNumber++) {
15+
result = result.multiply(BigInteger.valueOf(currentNumber));
16+
}
17+
18+
return result;
19+
}
20+
21+
// Usage:
22+
int number = 6;
23+
System.out.println(factorial(number)); // 720 = 6*5*4*3*2
24+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /