Skip to content

Instantly share code, notes, and snippets.

View sks147's full-sized avatar

Sumit Kumar Singh sks147

View GitHub Profile
@sks147
sks147 / last_modified.rb
Created June 27, 2016 06:45
Getting metadata of a file using ruby
# pass file arguments in double quotes
# e.g last_modified("/etc/passwd")
def last_modified(file)
t1 = File.stat(file).ctime
t2 = Time.now
elapsed = (t2-t1)/(60*60*24)
puts "#{file} was modified #{elapsed} days ago."
end

Keybase proof

I hereby claim:

  • I am sks147 on github.
  • I am sks147 (https://keybase.io/sks147) on keybase.
  • I have a public key whose fingerprint is 4F25 6418 4029 FC03 7E18 FC2F AB61 1170 3BDD E734

To claim this, I am signing this object:

@sks147
sks147 / HTTPConnectionReader.java
Last active September 22, 2016 05:51
Read all data from the http connection and write it to a temporary file created on your local system
import java.util.*;
import java.lang.*;
import java.io.*;
import java.net.*;
import java.awt.Desktop;
// Read all data from the http connection and write it to a temporary
// file created on your local system
public class HTTPConnectionReader{
public static void main (String[] args){
#include <iostream>
using namespace std;
int server_start_index;
int server_end_index;
int main(){
string url;
cin>>url;
cout << "Retrieving the server :" << endl;
@sks147
sks147 / URLDownloader.java
Last active September 22, 2016 06:09
Determine the Server Side MIME type information and Spawn an external viewer to display the file.
import java.util.*;
import java.lang.*;
import java.io.*;
import java.net.*;
import java.awt.Desktop;
//Determine the Server Side MIME type information and Spawn an external viewer to display the file.
public class URLDownloader{
public static void main (String[] args){
URL u = null;
#include <string>
#include <iostream>
using namespace std;
int main(){
string s;
cin>>s;
string s1;
s1=s;
//Simulating selective repeat sliding window protocol
#include <iostream>
#include <cstdlib>
using namespace std;
void receiver(int r);
int sent_packets=0;
int received_packets=0;
bool ack;
void sender()
{
@sks147
sks147 / HTTPClient.java
Last active September 22, 2016 06:15
Create a socket that is connected to port 80(HTTP)
import java.net.*;
import java.io.*;
//Create a socket that is connected to port 80(HTTP)
public class HTTPClient{
public static void main(String args[]){
Socket socket = null;
String hostname = "www.google.com";
int port = 80;
try{
socket = new Socket(hostname, port);
@sks147
sks147 / GETMethod.java
Created September 22, 2016 03:16
Send a request to www server using the HTTP protocol format using GET method.
import java.io.*;
import java.net.*;
import java.util.*;
//Send a request to www server using the HTTP protocol format using GET method
public class GETMethod{
public static void main(String args[]){
URL u = null;
try{
u = new URL("http://www.bbc.co.uk/accessibility/guides/");
HttpURLConnection http = (HttpURLConnection) u.openConnection();
@sks147
sks147 / ConsoleChatClient.java
Created October 5, 2016 12:04
Client Implementation of Chat Server
import java.io.*;
import java.net.*;
public class ConsoleChatClient {
public static void main(String[] args) throws IOException {
new ConsoleChatClient().chat();
}
protected Socket sock;
protected BufferedReader is;