This file contains hidden or 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
#include <stdio.h> | |
#include <poll.h> | |
#include <fcntl.h> | |
int main() { | |
int fd = open("/dev/null", O_WRONLY); | |
struct pollfd pollfds = { fd, POLLOUT, 0 }; | |
if (fd < 0) { | |
perror("open"); |
This file contains hidden or 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
import org.junit.Test; | |
import java.net.InetAddress; | |
import java.net.InetSocketAddress; | |
import java.net.Socket; | |
import java.net.SocketException; | |
/** | |
* This tests make sure Java prevents a socket from connecting to itself | |
* via binding to the same port it connects to |
This file contains hidden or 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
package main | |
import "fmt" | |
import "net" | |
var localhost = net.ParseIP("127.0.0.1") | |
var port1, port2 = 1220, 1229 | |
func conwrite() { | |
c1, err := net.DialTCP("tcp", &net.TCPAddr{localhost, port2}, &net.TCPAddr{localhost, port1}) |
This file contains hidden or 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
package cp | |
import ( | |
"io" | |
"os" | |
) | |
func cp(dst, src string) error { | |
s, err := os.Open(src) | |
if err != nil { |
This file contains hidden or 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
package main | |
import ( | |
"io" | |
"os" | |
"time" | |
) | |
func singLine(line string,w io.Writer) { | |
time.Sleep(time.Second) |
This file contains hidden or 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
package main | |
import ("bufio" | |
"fmt" | |
"io" | |
"net/http" | |
"net" | |
"strings") | |
type readFirstCloseSecond struct { |
This file contains hidden or 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
package main | |
// run this file with `go run clientDoGzip.go, and then file tmp.out to verify body is gzipped | |
import "net/http" | |
import "io/ioutil" | |
import "bytes" | |
import "fmt" | |
import "log" | |
import "compress/gzip" |
This file contains hidden or 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
class BencodeWriter { | |
static class SizedInputStream { | |
public InputStream stream; | |
public int size; | |
public SizedInputStream(InputStream _stream,int _size) {stream = _stream;size = _size;} | |
} | |
public static class BencodeProducer { | |
private OutputStream out; | |
public BencodeProducer(OutputStream o) {out = o;} |
This file contains hidden or 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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
// weird exercise from a friend | |
// need to Implement this struct | |
typedef struct attrib_t { | |
struct attrib_t* bytes[256]; | |
const char *data; |
This file contains hidden or 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
/** | |
* Trying to recreate the "Holder" class publishing error from JCIP. | |
* See http://stackoverflow.com/a/6812936/55094 for the description of the problem. | |
*/ | |
public class Publishing { | |
static class Holder { | |
int h = 0; | |
int dummy = 0; | |
public Holder(int h) { | |
for (long i=0;i<1000*1000;i++) { |