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
template<typename T> | |
void random_shuffle(std::vector<T>& elems) | |
{ | |
for (int i = 1; i < elems.size(); ++i) | |
{ | |
int index = rand() % (i + 1); | |
if (index != i) | |
{ | |
swap(elems[i], elems[index]); | |
} |
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
typedef pair<int, int> Elem; | |
bool compare(const Elem& lhs, const Elem& rhs) | |
{ | |
return lhs.first < rhs.first; | |
} | |
int main() | |
{ | |
vector<ifstream*> files; |
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
<html> | |
<head> | |
<script> | |
window.onload = function() { | |
var test_elem = document.getElementById('test'); | |
var number = 1; | |
test_elem.innerText = number; | |
setInterval(function() { | |
++number; | |
test_elem.innerText = number; |
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 gevent.server | |
def handle(socket, addr): | |
print addr | |
while True: | |
try: | |
content = socket.recv(1024) | |
if len(content) == 0: | |
break |
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
#! /usr/bin/env python | |
# | |
# The grammar for the parsed language is very simple. | |
# It's like a JSON variation. | |
# Here's a simple valid expression: | |
# { | |
# a 1, | |
# b 2, | |
# c { | |
# c_1 3, |
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 pprint | |
if __name__ == '__main__': | |
proc_net_file = open('/proc/net/dev') | |
field_values = {} | |
for l in proc_net_file: | |
if ':' in l: | |
head_content = l.split(':') |
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
// This program simply gets the ip for the specified interface. | |
#include <iostream> | |
#include <sys/ioctl.h> | |
#include <net/if.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
using namespace std; |
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
#! /usr/bin/expect -f | |
set host [lindex $argv 0] | |
set user [lindex $argv 1] | |
set pwsd [lindex $argv 2] | |
spawn ssh $user@$host | |
expect "yes/no" { | |
send "yes\r" |
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
/* | |
This exmple program provides a trivial echo server program that listens for TCP. | |
Where possible, it exits cleanly in response to a SIGINT (ctrl-c). | |
*/ | |
#include <string.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include <signal.h> |
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 sys | |
if __name__ == '__main__': | |
file1, file2 = sys.argv[1:] | |
file1_fd = open(file1) | |
file2_fd = open(file2) | |
line1 = file1_fd.readline() | |
line2 = file2_fd.readline() |