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
# Echo server program | |
import socket | |
HOST = '' # Symbolic name meaning all available interfaces | |
PORT = 50007 # Arbitrary non-privileged port | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.bind((HOST, PORT)) | |
s.listen(1) | |
conn, addr = s.accept() |
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
#include <pthread.h> | |
struct rwlock { | |
pthread_mutex_t lock; | |
pthread_cond_t read, write; | |
unsigned readers, writers, read_waiters, write_waiters; | |
}; | |
void reader_lock(struct rwlock *self) { | |
pthread_mutex_lock(&self->lock); |
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
// Copyright 2009 The Go Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style | |
// license that can be found in the LICENSE file. | |
package sync | |
import ( | |
"sync/atomic" | |
"unsafe" | |
) |
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
package hello; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.security.KeyStore; | |
import java.security.cert.Certificate; | |
import java.security.cert.CertificateFactory; | |
import javax.net.ssl.SSLContext; |
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
import java.net.InetAddress; | |
import java.net.UnknownHostException; | |
public class TestNet { | |
public static void main(String[] args) throws UnknownHostException { | |
InetAddress[] machines = InetAddress.getAllByName("lbs.yxgslb.netease.com"); | |
for (InetAddress address : machines) { | |
System.out.println(address.getHostAddress()); | |
} |
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
package main | |
import ( | |
"net" | |
"fmt" | |
"io" | |
"bytes" | |
"os" | |
) |
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
import webbrowser | |
import os | |
def openWeb(url): | |
webbrowser.open_new_tab(url) | |
def main(): | |
urls = ['http://www.baidu.com', 'http://www.bing.com', 'http://www.zhihu.com'] | |
for url in urls: | |
option = raw_input('open %s Y/N: ' %url) |
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
type CopyCb func(written int64) | |
func CopyWithCb(dst io.Writer, src io.Reader, cb CopyCb) (written int64, err error) { | |
for { | |
n, err := io.CopyN(dst, src, KB) | |
written += n | |
cb(written) | |
if err != nil { | |
if err == io.EOF { | |
return written, nil | |
} |
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
@RequestMapping(value="/pdfmethod", produces="application/pdf") | |
public void pdfMethod(HttpServletRequest request, HttpServletResponse response){ | |
response.setContentType("application/pdf"); | |
InputStream inputStream = null; | |
OutputStream outputStream = null; | |
try{ | |
inputStream = getInputStreamFromYourPdfFile(); | |
outputStream = response.getOutputStream(); | |
IOUtils.copy(inputStream, outputStream); | |
}catch(IOException ioException){ |
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
@RequestMapping( | |
value = "/{id}.json", | |
method = RequestMethod.GET, | |
produces = "application/json") | |
@ResponseBody | |
public Person getDetailsAsJson(@PathVariable Long id) { | |
return personRepo.findOne(id); | |
} | |
@RequestMapping( |
OlderNewer