Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added dart language,category,snippets #99

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/even-filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Filter a List
description: Filters a list to include only even numbers.
author: Vrindtime
tags: dart,collections,list,utility
---

```dart
final numbers = [1, 2, 3, 4, 5, 6];
final evens = numbers.where((n) => n.isEven).toList();
print(evens); // Prints [2, 4, 6]
```
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/find-index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Find Index of an Element
description: Finds and prints the index of a specific element in an array.
author: Vrindtime
tags: dart,array-manipulation,utility
---

```dart
final numbers = [10, 20, 30, 40, 50];
final index = numbers.indexOf(30);
print(index); // Prints 2
```
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/max-value.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Find Maximum in an Array
description: Finds and prints the maximum value in an array.
author: Vrindtime
tags: dart,array-manipulation,utility
---

```dart
final numbers = [3, 7, 2, 9, 4];
final maxNumber = numbers.reduce((a, b) => a > b ? a : b);
print(maxNumber); // Prints 9
```
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/remove-duplicate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Remove Duplicates from an Array
description: Removes duplicate elements from an array and prints the result.
author: Vrindtime
tags: dart,array-manipulation,utility
---

```dart
final numbers = [1, 2, 2, 3, 4, 4, 5];
final uniqueNumbers = numbers.toSet().toList();
print(uniqueNumbers); // Prints [1, 2, 3, 4, 5]
```
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/remove-element.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Remove Specific Element from an Array
description: Removes a specific element from an array and prints the result.
author: Vrindtime
tags: dart,array-manipulation,utility
---

```dart
final numbers = [1, 2, 3, 4, 5];
numbers.remove(3);
print(numbers); // Prints [1, 2, 4, 5]
```
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/reverse-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Reverse an Array
description: Reverses an array and prints the result.
author: Vrindtime
tags: dart,array-manipulation,utility
---

```dart
final numbers = [1, 2, 3, 4, 5];
final reversed = numbers.reversed.toList();
print(reversed); // Prints [5, 4, 3, 2, 1]
```
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/shuffle-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Shuffle an Array
description: Randomly shuffles the elements of an array and prints the result.
author: Vrindtime
tags: dart,array-manipulation,utility
---

```dart
final numbers = [1, 2, 3, 4, 5];
numbers.shuffle(Random());
print(numbers); // Prints the array in random order
```
12 changes: 12 additions & 0 deletions snippets/dart/array-manipulation/sort-array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Sort an Array
description: Sorts an array in ascending order and prints it.
author: Vrindtime
tags: dart,array-manipulation,utility
---

```dart
final numbers = [5, 1, 8, 3, 2];
numbers.sort();
print(numbers); // Prints [1, 2, 3, 5, 8]
```
10 changes: 10 additions & 0 deletions snippets/dart/basics/hello-world.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Hello, World!
description: Prints Hello, World! to the terminal.
author: Vrindtime
tags: dart,printing,hello-world,utility
---

```dart
print("Hello, World!"); // Prints Hello, World! to the console
```
12 changes: 12 additions & 0 deletions snippets/dart/date-and-time/add-duration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Add Duration to DateTime
description: Adds a specified duration to a DateTime object and prints the result.
author: Vrindtime
tags: dart,date-time,utility
---

```dart
final now = DateTime.now();
final future = now.add(Duration(days: 7,hours: 10,minutes: 5,seconds: 2,microseconds: 100,milliseconds: 50));
print(future); // Prints the date and time 7 days, 10 hours, 5 minutes, 2 seconds, 100 microseconds and 50 miliseconds from now
```
12 changes: 12 additions & 0 deletions snippets/dart/date-and-time/format-date.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Format DateTime
description: Formats a DateTime object into a human-readable string.
author: Vrindtime
tags: dart,date-time,utility
---

```dart
final now = DateTime.now();
final formattedDate = DateFormat('yyyy-MM-dd – kk:mm').format(now);
print(formattedDate); // Prints the formatted date, e.g., "2025-01-01 – 14:35"
```
11 changes: 11 additions & 0 deletions snippets/dart/date-and-time/get-date-time.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Get Current Date and Time
description: Retrieves and prints the current date and time.
author: Vrindtime
tags: dart,date-time,utility
---

```dart
final now = DateTime.now();
print(now); // Prints the current date and time
```
12 changes: 12 additions & 0 deletions snippets/dart/date-and-time/string-to-date.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Parse Date from String
description: Parses a date string into a DateTime object and prints it.
author: Vrindtime
tags: dart,date-time,utility
---

```dart
final dateString = "2025-01-01 15:30:00";
final parsedDate = DateTime.parse(dateString);
print(parsedDate); // Prints "2025-01-01 15:30:00.000"
```
14 changes: 14 additions & 0 deletions snippets/dart/date-and-time/time-difference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Calculate Time Difference
description: Calculates the difference between two DateTime objects in days, hours, and minutes.
author: Vrindtime
tags: dart,date-time,utility
---

```dart
final start = DateTime(2025, 1, 1, 12, 0);
final end = DateTime(2025, 1, 2, 14, 30);
final difference = end.difference(start);
print('Days: ${difference.inDays}, Hours: ${difference.inHours}, Minutes: ${difference.inMinutes}');
// Prints "Days: 1, Hours: 26, Minutes: 1590"
```
12 changes: 12 additions & 0 deletions snippets/dart/file-manipulation/append-to-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Append to a File
description: Appends text to an existing file and prints a confirmation.
author: Vrindtime
tags: dart,file-manipulation,io,utility
---

```dart
final file = File('example.txt');
await file.writeAsString('Appended text.', mode: FileMode.append); //remember to use aync modifier in the function
print('Text appended successfully.');
```
16 changes: 16 additions & 0 deletions snippets/dart/file-manipulation/delete-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: Delete a File
description: Deletes a specified file and prints a confirmation.
author: Vrindtime
tags: dart,file-manipulation,io,utility
---

```dart
final file = File('example.txt');
if (await file.exists()) {
await file.delete(); //remember to use aync modifier in the function
print('File deleted successfully.');
} else {
print('File does not exist.');
}
```
14 changes: 14 additions & 0 deletions snippets/dart/file-manipulation/list-files-directory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: List Files in a Directory
description: Lists all files in a directory and prints their names.
author: Vrindtime
tags: dart,file-manipulation,io,utility
---

```dart
final directory = Directory.current;
final files = directory.listSync();
for (var file in files) {
print(file.path); // Prints the paths of all files and directories
}
```
12 changes: 12 additions & 0 deletions snippets/dart/file-manipulation/read-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Read a File
description: Reads the content of a file and prints it to the console.
author: Vrindtime
tags: dart,file-manipulation,io,utility
---

```dart
final file = File('example.txt');
final content = await file.readAsString();
print(content); // Prints the content of the file
```
12 changes: 12 additions & 0 deletions snippets/dart/file-manipulation/write-file.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Write to a File
description: Writes text to a file and prints a confirmation.
author: Vrindtime
tags: dart,file-manipulation,io,utility
---

```dart
final file = File('example.txt');
await file.writeAsString('Hello, Dart!'); //remember to use aync modifier in the function
print('File written successfully.');
```
11 changes: 11 additions & 0 deletions snippets/dart/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/contain-string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Check if String Contains Substring
description: Checks if a string contains a specific substring and prints the result.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final input = 'Learning Dart is fun!';
final contains = input.contains('Dart');
print(contains); // Prints true
```
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/convert-to-uppercase.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Convert to Uppercase
description: Converts a string to uppercase and prints it.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final original = "hello, world!";
final uppercased = original.toUpperCase();
print(uppercased); // Prints "HELLO, WORLD!"
```
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/count-character.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Count Characters in a String
description: Counts the number of characters in a string and prints the result.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final input = 'Dart';
final length = input.length;
print(length); // Prints 4
```
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/extract-substring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Extract Substring
description: Extracts a portion of a string and prints the result.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final input = 'Hello, Dart!';
final substring = input.substring(7, 11);
print(substring); // Prints 'Dart'
```
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/isString-palindrome.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Check if a String is a Palindrome
description: Checks if a string is a palindrome and prints the result.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final input = 'madam';
final isPalindrome = input == input.split('').reversed.join('');
print(isPalindrome); // Prints true
```
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/replace-substring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Replace Substring
description: Replaces all occurrences of a substring with another substring and prints the result.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final input = 'Dart is great!';
final replaced = input.replaceAll('great', 'awesome');
print(replaced); // Prints 'Dart is awesome!'
```
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/reverse-string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Reverse a String
description: Reverses a string and prints the result.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final input = 'Dart';
final reversed = input.split('').reversed.join('');
print(reversed); // Prints 'traD'
```
12 changes: 12 additions & 0 deletions snippets/dart/string-manipulation/split-string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Split String by Delimiter
description: Splits a string into a list of substrings using a delimiter and prints the result.
author: Vrindtime
tags: dart,string-manipulation,utility
---

```dart
final input = 'apple,banana,cherry';
final fruits = input.split(',');
print(fruits); // Prints [apple, banana, cherry]
```
Loading
Loading