-
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-12-05 17:13:54.476866 new snippets
- Loading branch information
1 parent
50ecff0
commit bc8aa1d
Showing
21 changed files
with
557 additions
and
873 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,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 |
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,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()); | ||
} | ||
} | ||
} |
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,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); | ||
} | ||
} | ||
} |
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,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" |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.