Skip to content

Instantly share code, notes, and snippets.

public class Speed {
private final File FOLDER = new File("Files");
String name = "movie.mp4";
int port = 46789;
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(port);
serverSocket.setReuseAddress(true);
Socket socket = serverSocket.accept();
byte[] buffer = new byte[1024*1024];
@SatyaSnehith
SatyaSnehith / FileChooserDialog.java
Created December 4, 2017 18:37
File Chooser Dialog for Android
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.ActionMode;
import android.view.LayoutInflater;
@SatyaSnehith
SatyaSnehith / Converter.java
Last active September 28, 2024 17:58
Convert Bytes to KB, MB, GB, TB - java
public class Converter{
static long kilo = 1024;
static long mega = kilo * kilo;
static long giga = mega * kilo;
static long tera = giga * kilo;
public static void main(String[] args) {
for (String arg: args) {
try {
System.out.println(getSize(Long.parseLong(arg)));
@SatyaSnehith
SatyaSnehith / Stopwatch.java
Last active January 21, 2022 12:36
Stopwatch application in JavaFX
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
@SatyaSnehith
SatyaSnehith / Server.java
Last active November 9, 2018 14:39
This Server accepts requests and sends information
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Server {
private ServerSocket serverSocket = null;
private Socket socket = null;
private ServerThread serverThread;
Server(int port) {
@SatyaSnehith
SatyaSnehith / Ip.java
Created November 8, 2018 17:01
Get IP Address of a Device
import java.net.*;
import java.util.*;
public class Ip {
public static void main(String[] args) {
getIPAddress();
}
String getSubnetAddress(String ip) {
@SatyaSnehith
SatyaSnehith / Connection.java
Created February 28, 2019 13:49
Acts as Server
package sample;
import java.awt.*;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class Connection extends Thread {
final int PORT = 12345;
private boolean isRunning = true;
@SatyaSnehith
SatyaSnehith / ListFile.java
Last active May 4, 2020 11:26
Get organization name from mac address prefix. compile and run "java ListFile <mac address prefix(multiple)>. file:https://drive.google.com/file/d/16a1oCASZcM6NUU7t2dVKYFYi4D9_kvKY/view?usp=sharing
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class ListFile {
String fileName = "address_book.txt";
List<String> list;
ListFile() {
@SatyaSnehith
SatyaSnehith / address-book.txt
Created May 17, 2020 08:33
Mac Prefix Vendor Name
This file has been truncated, but you can view the full file.
000000 XEROX CORPORATION
000001 XEROX CORPORATION
000002 XEROX CORPORATION
000003 XEROX CORPORATION
000004 XEROX CORPORATION
000005 XEROX CORPORATION
000006 XEROX CORPORATION
000007 XEROX CORPORATION
000008 XEROX CORPORATION
000009 XEROX CORPORATION
@SatyaSnehith
SatyaSnehith / ExecutionTimer.java
Created February 4, 2021 14:40
find out the execution time of a block of code or whole program
public class ExecutionTimer {
private static long startTime;
static {
startTime = -1;
}
public static void startTimer() {
startTime = System.currentTimeMillis();
}