Skip to content

Commit e61dd65

Browse files
authored
Merge branch 'dostonnabotov:main' into main
2 parents 382b4d2 + 50f31a7 commit e61dd65

File tree

7 files changed

+73
-13
lines changed

7 files changed

+73
-13
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Here’s an example for JavaScript:
117117
title: Format Date
118118
description: Formats a date in 'YYYY-MM-DD' format.
119119
author: dostonnabotov
120-
tags: javascript,date,format
120+
tags: date,format
121121
---
122122

123123
```js

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Here's an example for JavaScript:
6363
title: Format Date
6464
description: Formats a date in 'YYYY-MM-DD' format.
6565
author: dostonnabotov
66-
tags: javascript,date,format
66+
tags: date,format
6767
---
6868

6969
```js

public/icons/bash.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Kill Previous Instances
3+
description: Kill all previous instances of a script
4+
author: saminjay
5+
tags: kill,process,background
6+
---
7+
8+
```bash
9+
function kill_prev() {
10+
# $$ contains current pid (grep ignore so it doesn't suicide)
11+
local processes
12+
readarray -t processes < <(pgrep -f "$0" | grep -v "$$")
13+
kill "${processes[@]}" >/dev/null 2>&1
14+
}
15+
16+
# Usage:
17+
# Add this function to your background running script
18+
# It will make sure that only one instance of your script is running at a time
19+
kill_prev
20+
```

snippets/bash/system/system-resource-monitor.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ system_resources () {
1515

1616
system_resources "$@"
1717

18-
// Usage:
19-
chmod a+x system-resource-monitor.sh // First make it executable for all the users
18+
# Usage:
19+
chmod a+x system-resource-monitor.sh # First make it executable for all the users
2020

21-
./system-resource-monitor.sh // It will print the following system resources (CPU, RAM, disk, and active users)
21+
./system-resource-monitor.sh # It will print the following system resources (CPU, RAM, disk, and active users)
2222
```

snippets/css/animations/pulse-animation.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@ title: Pulse Animation
33
description: Adds a smooth pulsing animation with opacity and scale effects
44
author: AlsoKnownAs-Ax
55
tags: animation,pulse,pulse-scale
6+
contributors: alanb4rt
67
---
78

89
```css
910
.pulse {
10-
animation: pulse 2s ease-in-out infinite;
11+
animation: pulse 1s ease-in-out infinite alternate;
1112
}
1213

1314
@keyframes pulse {
14-
0% {
15+
from {
1516
opacity: 0.5;
1617
transform: scale(1);
1718
}
18-
50% {
19+
to {
1920
opacity: 1;
2021
transform: scale(1.05);
2122
}
22-
100% {
23-
opacity: 0.5;
24-
transform: scale(1);
25-
}
2623
}
2724
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Get Desktop Enviroment
3+
description: Get the Desktop Enviroment that the user is currently using.
4+
author: sponkurtus2
5+
tags: linux,file
6+
---
7+
8+
```rust
9+
fn get_desktop_env() -> String {
10+
// Return empty string if no X display is available
11+
if env::var("DISPLAY").is_err() {
12+
return String::new();
13+
}
14+
15+
// Check common desktop environment variables.
16+
for env_var in &[
17+
"XDG_SESSION_DESKTOP",
18+
"XDG_CURRENT_DESKTOP",
19+
"DESKTOP_SESSION",
20+
] {
21+
if let Ok(de) = env::var(env_var) {
22+
return de;
23+
}
24+
}
25+
26+
// As fallback, try to get desktop name from last word of last line in .xinitrc
27+
let path = format!("{}/.xinitrc", env::var("HOME").unwrap_or_default());
28+
if let Ok(mut file) = File::open(&path) {
29+
let mut buf = String::new();
30+
if file.read_to_string(&mut buf).is_ok() {
31+
if let Some(last_line) = buf.lines().last() {
32+
let last_word = last_line.split(' ').last().unwrap_or("");
33+
return last_word.to_string();
34+
}
35+
}
36+
}
37+
38+
// Return "N/A" if no desktop environment could be detected
39+
String::from("N/A")
40+
}
41+
42+
// Usage:
43+
get_desktop_env(); // Returns: the desktop enviroment that the user actually has e.g. i3.
44+
```

0 commit comments

Comments
 (0)