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 <stdio.h> | |
#include <stdlib.h> | |
static char * | |
read_stdin (void) | |
{ | |
size_t cap = 4096, /* Initial capacity for the char buffer */ | |
len = 0; /* Current offset of the buffer */ | |
char *buffer = malloc(cap * sizeof (char)); | |
int c; |
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
var fs = require('fs'); | |
function BufferWriter(initialSize) { | |
initialSize = initialSize || 1024; | |
this.data = new Buffer(initialSize); | |
this.clear(this.data); | |
this.capacity = initialSize; | |
this.offset = 0; | |
} |
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
#!/usr/bin/python2 | |
from threading import Thread | |
import socket | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect(('localhost', 9999,)) | |
class ReplyHandler(Thread): |
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
/* Tested on Linux running apache 2.4.10-1 CGI module | |
and bash-4.3.018-1 */ | |
#include <stdio.h> | |
#include <assert.h> | |
#include <unistd.h> | |
#include <sys/socket.h> | |
#include <netdb.h> | |
#define HOST "127.0.0.1" |
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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <stdint.h> | |
#include <unistd.h> | |
typedef struct { | |
int64_t user, nice, system, | |
idle, iowait, irq, | |
softirq, steal, guest, |
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 <iostream> | |
#include <fstream> | |
class Twister { | |
private: | |
uint32_t data[624], | |
index = 0; | |
uint32_t read_device() { | |
std::ifstream ifs("/dev/urandom"); | |
uint32_t r(0); |
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
// SFINAE structure that tests if a given | |
// type contains the iterator typedef | |
template<typename T> | |
struct has_iterator { | |
template<class C> | |
static char test(typename C::iterator*); | |
static long test(...); | |
enum { | |
value = 1 == sizeof test<T>(0) |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title></title> | |
<meta name="description" content=""> | |
<meta name="author" content=""> | |
<style> | |
#canvas { | |
border: 1px solid; |
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 <iostream> | |
#include <stdexcept> | |
struct RangeIterator { | |
int64_t i, s = 1; | |
const RangeIterator &operator++() { | |
i += s; | |
return *this; | |
} | |
const bool operator!=(const RangeIterator &it) { |
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 <iostream> | |
#include <cmath> | |
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr> | |
bool is_prime(T n) { | |
if (n < 2) { | |
return false; | |
} | |
for (T i = 2, sq = sqrt(n) + 1; i != sq; i++) { | |
if (n % i == 0) { |