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
#ifndef OBJECT_H_ | |
#define OBJECT_H_ | |
#define OBJECT_INHERIT \ | |
void *(**vtable)(); \ | |
const char *name; | |
typedef struct object { | |
OBJECT_INHERIT | |
} OBJECT; | |
enum |
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
fib :: (Num a, Integral a) => a -> Integer | |
fib = snd . fastfib | |
where fastfib :: (Num a, Integral a) => a -> (Integer, Integer) | |
fastfib 0 = (0, 0) | |
fastfib 1 = (0, 1) | |
fastfib n | |
| n `mod` 2 == 1 = ((a + c) * b, (c*c) + (b*b)) | |
| otherwise = ((a*a) + (b*b), (a + c) * b) | |
where d = fastfib (n `div` 2) | |
a = fst d |
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
7 main :: IO() | |
6 main = do | |
5 | |
4 forM [1000000..5000000] $ \x -> do | |
3 a <- getCPUTime | |
2 return $! fib x | |
1 b <- getCPUTime | |
0 putStrLn $ show ((b-a) `div` 10^9) | |
=============================================================== |
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
20 fib :: (Num a, Integral a) => a -> Integer |@ | |
19 fib = snd . fastfib |@ | |
18 where fastfib :: (Num a, Integral a) => a -> (Integer, Integer) |@ | |
17 fastfib 0 = (0, 0) |@ | |
16 fastfib 1 = (0, 1) |@ | |
15 fastfib n |@ | |
14 | n `mod` 2 == 1 = ((a + c) * b, (c*c) + (b*b)) |@ | |
13 | otherwise = ((a*a) + (b*b), (a + c) * b) |@ | |
12 where d = fastfib (n `div` 2) |@ | |
11 a = fst d |@ |
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
0 _ = require 'underscore' | |
1 TRUE = (a,b) -> a | |
2 FALSE = (a,b) -> b | |
3 NAND = (a,b) -> a(b,a)(FALSE, TRUE) | |
4 NOT = (a) -> NAND(a,a) | |
5 AND = (a,b) -> NOT(NAND(a,b)) | |
6 OR = (a,b) -> NAND(NOT(a),NOT(b)) | |
7 NOR = (a,b) -> NOT(OR(a,b)) | |
8 XOR = (a,b) -> NOR(AND(a,b),NOR(a,b)) | |
9 XNOR = (a,b) -> NOT(XOR(a,b)) |
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
<script> | |
$(function() { | |
$('.item').bind('touchstart', function (e) { | |
$(e.srcElement).addClass('touched'); | |
}); | |
$('.item').bind('touchmove', function (e) { | |
$(e.srcElement).removeClass('touched'); | |
}); | |
$('.item').bind('touchend', function (e) { | |
$(e.srcElement).removeClass('touched'); |
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
<script> | |
$(function() { | |
$('.item').bind('touchstart', function (e) { | |
$(e.srcElement).addClass('touched'); | |
}); | |
$('.item').bind('touchmove', function (e) { | |
$(e.srcElement).removeClass('touched'); | |
}); | |
$('.item').bind('touchend', function (e) { | |
$(e.srcElement).removeClass('touched'); |
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 "server.h" | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
#include <netinet/in.h> | |
#include <fcntl.h> | |
static void io_cb(struct ev_loop *loop, struct ev_io *watcher, int events) | |
{ | |
if (events & EV_WRITE) |
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.io.IOException; | |
import java.net.InetSocketAddress; | |
import java.nio.ByteBuffer; | |
import java.nio.channels.SelectionKey; | |
import java.nio.channels.Selector; | |
import java.nio.channels.ServerSocketChannel; | |
import java.nio.channels.SocketChannel; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.ScheduledExecutorService; | |
import java.util.concurrent.TimeUnit; |
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
void accept_cb(EV_P_ ev_io *io, int revents) | |
{ | |
int client_fd; | |
socklen_t len; | |
struct sockaddr_in client_addr; | |
len = sizeof(client_addr); | |
client_fd = accept(io->fd, (struct sockaddr *)&client_addr, &len); | |
fcntl(client_fd, F_SETFL, O_NONBLOCK); |
OlderNewer