Skip to content

Commit

Permalink
2024-12-05 17:13:54.476866 new snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardocerqueira committed Dec 5, 2024
1 parent 50ecff0 commit bc8aa1d
Show file tree
Hide file tree
Showing 21 changed files with 557 additions and 873 deletions.
35 changes: 35 additions & 0 deletions seeker/report.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
--------------------------------------------------------------------------------
2024-12-05 17:13:54.476866
--------------------------------------------------------------------------------
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: snippet/DS_CodingChallengeSolution_VaibhavSharma
deleted: snippet/UDPClient.java
deleted: snippet/UDPServer.java
deleted: snippet/get_list_of_suites_with_tag.py
modified: snippet/headline.zsh
deleted: snippet/lol_worlds_simulator.py
deleted: snippet/ola.py
deleted: snippet/read_csv_with_pandas.py
deleted: snippet/reset-foundry-version-to-monorepo.sh
deleted: snippet/ssh_hole.sh

Untracked files:
(use "git add <file>..." to include in what will be committed)
snippet/.bashrc
snippet/IRCClient.java
snippet/IRCServer.java
snippet/RandomizePlaylist.sh
snippet/fix_labs.py
snippet/go-install.sh
snippet/modbusserver.py
snippet/mount_vbox_shared_folder.sh
snippet/run1
snippet/yaml_merger.py

no changes added to commit (use "git add" and/or "git commit -a")

--------------------------------------------------------------------------------
2024-12-04 17:13:54.644919
--------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions seeker/snippet/.bashrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#date: 2024-12-05T17:12:02Z
#url: https://api.github.com/gists/5cc903d166dcdc0cc7c545608454ec28
#owner: https://api.github.com/users/jcrtexidor

# ~/.bashrc

...
source ~/.cmd/mount_vbox_shared_folder.sh
79 changes: 0 additions & 79 deletions seeker/snippet/DS_CodingChallengeSolution_VaibhavSharma

This file was deleted.

47 changes: 47 additions & 0 deletions seeker/snippet/IRCClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//date: 2024-12-05T17:02:42Z
//url: https://api.github.com/gists/0cd5acc824db730c068a18840d18d8ba
//owner: https://api.github.com/users/acostaRossi

import java.io.*;
import java.net.*;

public class IRCClient {
private static final String SERVER_ADDRESS = "localhost";
private static final int SERVER_PORT = 6667;

public static void main(String[] args) {
try {
Socket socket = new Socket(SERVER_ADDRESS, SERVER_PORT);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Connesso al server IRC!");
System.out.println("Per uscire digita '/quit'");

// Thread per leggere i messaggi dal server
Thread serverListener = new Thread(() -> {
try {
String message;
while ((message = in.readLine()) != null) {
System.out.println(message);
}
} catch (IOException e) {
System.err.println("Connessione persa con il server.");
}
});
serverListener.start();

// Legge i messaggi dalla console e li invia al server
String userInput;
while ((userInput = console.readLine()) != null) {
out.println(userInput);
if (userInput.equalsIgnoreCase("/quit")) {
break;
}
}
} catch (IOException e) {
System.err.println("Errore nella connessione al server: " + e.getMessage());
}
}
}
93 changes: 93 additions & 0 deletions seeker/snippet/IRCServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//date: 2024-12-05T17:02:42Z
//url: https://api.github.com/gists/0cd5acc824db730c068a18840d18d8ba
//owner: https://api.github.com/users/acostaRossi

import java.io.*;
import java.net.*;
import java.util.*;

public class IRCServer {
private static final int PORT = 6667; // Porta standard IRC
private static Set<ClientHandler> clients = new HashSet<>();

public static void main(String[] args) {
System.out.println("IRC Server avviato sulla porta " + PORT);

try (ServerSocket serverSocket = new ServerSocket(PORT)) {
while (true) {
Socket clientSocket = serverSocket.accept();
System.out.println("Nuovo client connesso: " + clientSocket.getInetAddress());
ClientHandler clientHandler = new ClientHandler(clientSocket);
clients.add(clientHandler);
new Thread(clientHandler).start();
}
} catch (IOException e) {
System.err.println("Errore nel server: " + e.getMessage());
}
}

// Invia un messaggio a tutti i client connessi
public static void broadcast(String message, ClientHandler sender) {
for (ClientHandler client : clients) {
if (client != sender) {
client.sendMessage(message);
}
}
}

// Rimuove un client dalla lista quando si disconnette
public static void removeClient(ClientHandler clientHandler) {
clients.remove(clientHandler);
System.out.println("Client disconnesso.");
}

// Classe per gestire un singolo client
private static class ClientHandler implements Runnable {
private Socket socket;
private PrintWriter out;
private String nickname;

public ClientHandler(Socket socket) {
this.socket = socket;
}

@Override
public void run() {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);

// Richiede il nickname
out.println("Benvenuto nel server IRC! Inserisci il tuo nickname:");
nickname = in.readLine();
System.out.println(nickname + " si è unito alla chat.");
broadcast(nickname + " è entrato nella chat!", this);

// Legge i messaggi dal client
String message;
while ((message = in.readLine()) != null) {
if (message.equalsIgnoreCase("/quit")) {
break;
}
System.out.println(nickname + ": " + message);
broadcast(nickname + ": " + message, this);
}
} catch (IOException e) {
System.err.println("Errore con il client: " + e.getMessage());
} finally {
try {
socket.close();
} catch (IOException e) {
System.err.println("Errore durante la chiusura della connessione: " + e.getMessage());
}
removeClient(this);
broadcast(nickname + " ha lasciato la chat.", this);
}
}

// Invia un messaggio a questo client
public void sendMessage(String message) {
out.println(message);
}
}
}
44 changes: 44 additions & 0 deletions seeker/snippet/RandomizePlaylist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#date: 2024-12-05T17:06:03Z
#url: https://api.github.com/gists/181756472003152136f7bc0284a0dec1
#owner: https://api.github.com/users/Ne0n09

#!/bin/bash

# Run script with playlist name in the format of 'your playlist'
# If the playlist has spaces in the name put quotes around it

# Define the base directory
BASE_DIR="/home/fpp/media/playlists"

# Check if argument is provided
if [ -z "$1" ]; then
echo "Error: No playlist name provided. Please provide a playlist name."
exit 1
fi

# Set the PLAYLIST variable from the $1 argument
PLAYLIST="$1"

# Remove any surrounding spaces
PLAYLIST=$(echo "$PLAYLIST" | xargs)

# Construct the full file path
INPUT_FILE="$BASE_DIR/$PLAYLIST.json"

# Check if the playlist file exists
if [ ! -f "$INPUT_FILE" ]; then
echo "Error: File '$INPUT_FILE' not found in directory '$BASE_DIR'."
exit 1
fi

# Shuffle the JSON array using Python
python3 -c "
import json, random
with open('$INPUT_FILE', 'r') as f:
data = json.load(f)
data['mainPlaylist'] = random.sample(data['mainPlaylist'], len(data['mainPlaylist']))
with open('$INPUT_FILE', 'w') as f:
json.dump(data, f, indent=4)
"

echo "Randomized sequences written back to $INPUT_FILE"
44 changes: 0 additions & 44 deletions seeker/snippet/UDPClient.java

This file was deleted.

Loading

0 comments on commit bc8aa1d

Please sign in to comment.