-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-07-12 17:12:24.016161 new snippets
- Loading branch information
1 parent
d2dfd79
commit e87388b
Showing
21 changed files
with
1,133 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//date: 2024-07-12T16:48:43Z | ||
//url: https://api.github.com/gists/30efee98745cf1a8dde390307da4d6a6 | ||
//owner: https://api.github.com/users/avii-7 | ||
|
||
// Max sum in sub-arrays ( 2 ) | ||
|
||
// Problem Link: https://www.geeksforgeeks.org/problems/max-sum-in-sub-arrays0824/0 | ||
|
||
// Brute Force Approch | ||
|
||
// TC -> O(n * n) | ||
// SC -> O(1) | ||
|
||
// Thought Process | ||
// 1. I will generate all the sub-arrays. | ||
// 2. Whenever a new element is inserted into the range, check with smallest and second smallest number. | ||
// 3. After adjusting new number, if sum is greater than maxSum then maxSum will be replaced with sum. | ||
|
||
public static long pairWithMaxSum(long arr[], long N) | ||
{ | ||
long maxSum = 0; | ||
|
||
for (int i = 0; i < N; i++) { | ||
|
||
long s = Long.MAX_VALUE, ss = Long.MAX_VALUE; | ||
|
||
for (int j = i; j < N; j++) { | ||
|
||
if(arr[j] < s) { | ||
ss = s; | ||
s = arr[j]; | ||
} | ||
else if (arr[j] < ss) { | ||
ss = arr[j]; | ||
} | ||
|
||
long tSum = s + ss; | ||
|
||
if (tSum > maxSum) { | ||
maxSum = tSum; | ||
} | ||
} | ||
} | ||
|
||
return maxSum; | ||
} | ||
|
||
// Optimal Approch | ||
|
||
// TC-> O(n) | ||
// SC-> O(1) | ||
|
||
// Observation | ||
// 1. I found that smallest and second smallest number with in range i...j (where i < j) | ||
// with maximum sum is always contigous (next to one another). | ||
|
||
// Thought Process | ||
// 1. According to observation, we only need to find contigous elements whose sum is greater than others contigous elements. | ||
|
||
public static long pairWithMaxSum(long arr[], long N) | ||
{ | ||
long maxSum = 0; | ||
|
||
for (int i = 0; i <= N - 2; i++) { | ||
long tSum = arr[i] + arr[i + 1]; | ||
if(tSum > maxSum) { | ||
maxSum = tSum; | ||
} | ||
} | ||
|
||
return maxSum; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#date: 2024-07-12T16:43:12Z | ||
#url: https://api.github.com/gists/7de081cf9ae2073b9603e77eadb242c3 | ||
#owner: https://api.github.com/users/MaXVoLD | ||
|
||
students = {'Johnny', 'Bilbo', 'Steve', 'Khendrik', 'Aaron'} | ||
grades = [[5, 3, 3, 5, 4], [2, 2, 2, 3], [4, 5, 5, 2], [4, 4, 3], [5, 5, 5, 4, 5]] | ||
gpa = [sum(grades[0]) / len(grades[0]) , | ||
sum(grades[1]) / len(grades[1]) , | ||
sum(grades[2]) / len(grades[2]) , | ||
sum(grades[3]) / len(grades[3]) , | ||
sum(grades[4]) / len(grades[4]) ,] #Для каждого значения из списка нашел среднее значение. Составил новый список. | ||
sorted_student = sorted(students) #Отсортировал имена по порядку A-Z. Вернул значения множества списком. | ||
dict_gpa = dict(zip(sorted_student , gpa)) #Склеил оба списка между собой и объединил их в словарь. | ||
print(dict_gpa) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#date: 2024-07-12T16:49:09Z | ||
#url: https://api.github.com/gists/ef44453f2da72d2f55492b7d4c955d8d | ||
#owner: https://api.github.com/users/LeXofLeviafan | ||
|
||
#!/bin/bash | ||
# Usage: `bukuserver` starts up the server, `bukuserver --stop` sends TERM to the already running server | ||
# On startup, the user is offered to choose or create a new DB (cancel both to exit) | ||
# After the server stops (via CTRL+C or `bukuserver --stop`), the choice is given again | ||
# NOTE: requires Zenity to work | ||
|
||
: "${BUKUSERVER=$HOME/Work/buku/}" # path to executable, or directory to run from source | ||
: "${VENV:=$HOME/.local/share/bukuserver/venv}" # alternatively, can be set to $BUKUSERVER/venv | ||
BUKU_CONFIG_DIR=~/.local/share/buku | ||
|
||
# specify Web-UI settings here | ||
export BUKUSERVER_THEME=slate | ||
export BUKUSERVER_DISABLE_FAVICON=false | ||
export BUKUSERVER_OPEN_IN_NEW_TAB=true | ||
|
||
|
||
function _settermtitle { echo -en "\033]2;$1\007"; } # changes terminal title | ||
|
||
function _select-db { | ||
FILES=( ) | ||
while read FILE; do | ||
[ -e "$FILE" ] && FILES+=( "$(basename "${FILE%.db}")" ) | ||
done < <(ls -1 "$BUKU_CONFIG_DIR"/{,.}*.db 2>/dev/null | sort) | ||
FILE= | ||
if [ ${#FILES[@]} != 0 ]; then | ||
FILE=`zenity --list --title="Choose DB" --text="(or click Cancel to create new DB)" --column="Name" -- "${FILES[@]}"` | ||
[ "$FILE" ] && echo "$BUKU_CONFIG_DIR/$FILE.db" && return | ||
fi | ||
while true; do | ||
FILE=`zenity --entry --title="Create new DB?" --text="DB name (cannot contain '/'):" --entry-text="bookmarks"` | ||
! [ "$FILE" ] && echo "No name given, qutting" >&2 && return | ||
[[ "$FILE" == *'/'* ]] && zenity --error --text="DB name cannot contain '/'!" && continue | ||
[ -e "$BUKU_CONFIG_DIR/$FILE.db" ] && ! zenity --question --text="'$FILE' exists already. Open anyway?" && continue | ||
echo "$BUKU_CONFIG_DIR/$FILE.db" | ||
return | ||
done | ||
} | ||
|
||
|
||
if [ "$1" == '--stop' ]; then | ||
PID=`ps -afu "$USER" | grep '/python[^ ]* .*/bukuserver run$' | awk '{print $2}'` | ||
[ "$PID" ] && kill "$PID" | ||
exit | ||
fi | ||
|
||
_settermtitle 'bukuserver' | ||
|
||
if [ -d "$BUKUSERVER" ]; then | ||
cd "$BUKUSERVER" | ||
python -m venv "$VENV" | ||
. "$VENV/bin/activate" | ||
pip install .[server] | ||
BUKUSERVER='bukuserver' | ||
fi | ||
|
||
export BUKUSERVER_DB_FILE=`_select-db` | ||
while [ "$BUKUSERVER_DB_FILE" ]; do | ||
"$BUKUSERVER" run | ||
export BUKUSERVER_DB_FILE=`_select-db` | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#date: 2024-07-12T16:53:46Z | ||
#url: https://api.github.com/gists/b1e92b1eb4241818a13d9929fa88021a | ||
#owner: https://api.github.com/users/nyabongo | ||
|
||
#!/bin/bash | ||
|
||
show_help() { | ||
echo "Usage: $(basename "$0") [-h] [-i pattern] [-e pattern] [-v]" | ||
echo | ||
echo "Options:" | ||
echo " -h Show this help message" | ||
echo " -i pattern Ignore files matching the pattern (e.g., '*.g.dart')" | ||
echo " -e pattern Only include files matching the pattern (e.g., 'index.*')" | ||
echo " -v Enable verbose mode to print files not ignored" | ||
} | ||
|
||
ignore_pattern="" | ||
include_pattern="" | ||
verbose=false | ||
|
||
while getopts "hi:e:v" opt; do | ||
case $opt in | ||
h) | ||
show_help | ||
exit 0 | ||
;; | ||
i) | ||
ignore_pattern="$OPTARG" | ||
;; | ||
e) | ||
include_pattern="$OPTARG" | ||
;; | ||
v) | ||
verbose=true | ||
;; | ||
\?) | ||
show_help | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
output="" | ||
while IFS= read -r file; do | ||
# Check if the file matches the ignore pattern | ||
if [[ -n "$ignore_pattern" && "$file" == $ignore_pattern ]]; then | ||
continue | ||
fi | ||
|
||
# Check if the file matches the include pattern | ||
if [[ -n "$include_pattern" && ! "$file" == $include_pattern ]]; then | ||
continue | ||
fi | ||
|
||
if $verbose; then | ||
echo "Processing file: $file" | ||
fi | ||
|
||
file_type=$(file --mime-type -b "$file") | ||
output+="File: $file"$'\n' | ||
output+="Path: $(realpath --relative-to="$(pwd)" "$file")"$'\n' | ||
output+="Contents:"$'\n' | ||
if [[ "$file_type" == text/* ]]; then | ||
output+="\`\`\`"$'\n' | ||
output+="$(cat "$file")"$'\n' | ||
output+="\`\`\`"$'\n' | ||
else | ||
output+="<Binary file, content skipped>"$'\n' | ||
fi | ||
output+=$'\n'$'\n' | ||
done < <(git ls-files) | ||
echo "$output" | xclip -selection clipboard |
Oops, something went wrong.