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
""" | |
Provides an example on how to create a server script for blueberry. | |
""" | |
import os | |
import sys | |
from signal import SIGTERM | |
from optparse import OptionParser | |
from routes.middleware import RoutesMiddleware |
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 urllib2 | |
from urllib import urlencode | |
class APIRequest(urllib2.Request): | |
""" | |
Hack urllib2.Request so we can use custom HTTP requests like DELETE and PUT | |
""" | |
def set_method(self, method): | |
self.method = method.upper() |
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
;; this function is defined in vector_of_pairs.c and used in this file | |
(define vector_of_pairs (foreign-safe-lambda void "vector_of_pairs" int)) | |
;; define the scheme callback -- note that this is extern'd in vector_of_pairs.c | |
(define-external (scm_cb (scheme-object x)) void | |
(print x)) | |
;; call C function to generate vector of pairs, passing N into it | |
(vector_of_pairs 10) |
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 <sys/epoll.h> | |
#include <fcntl.h> | |
#include <string.h> | |
#include "chicken.h" | |
#define MAX_EVENTS 24 | |
extern void SCM_epoll_wait_cb(C_word vec); |
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
(define (write-handler fd) | |
;; epoll tells us to write to socket | |
(let ((buf (hash-table-ref fd-write-table fd))) | |
(##net#write fd buf (string-length buf))) | |
;; write prompt to client after sending buf | |
(##net#write fd "> " 2) | |
;; clear out write buffer | |
(hash-table-set! fd-write-table fd "") |
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
;; Is this a good way to "remove" elements from a list? It just builds a new | |
;; list after filtering out the element I want removed. | |
(define (filter-out-fd fd) | |
;; builds a new list after filtering out fd | |
(let loop ((li fd-list) (newlist '())) | |
(if (null? li) | |
newlist | |
(if (eq? fd (car li)) | |
(loop (cdr li) newlist) |
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
24,522,286 1 1 16,348,190 0 0 0 0 0 while (i < node_count) { | |
16,348,188 0 0 8,174,094 0 0 8,174,094 0 0 z = (struct rbt_node_s *)pmap; | |
24,522,282 0 0 8,174,094 0 0 8,174,094 0 0 pmap += sizeof(struct rbt_node_s); | |
. . . . . . . . . | |
24,522,282 0 0 16,348,188 0 0 8,174,094 3,064,773 3,064,773 z->strkey = pmap; | |
57,218,658 1 1 24,522,282 510,781 510,781 8,174,094 0 0 pmap += z->vlen+1; | |
. . . . . . . . . | |
24,522,282 0 0 16,348,188 6,962,690 6,962,690 8,174,094 0 0 poff = *(long *)pmap; | |
24,522,282 0 0 8,174,094 0 0 8,174,094 0 0 pmap += sizeof(long); | |
24,522,282 1 1 16,348,188 1,021,156 1,021,156 |
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
/* | |
* XXX: This code might not work as-is. I'm cutting and pasting the relevant | |
* parts from a working implementation in my hash tree project that may or may | |
* not get pushed to github later. That's why I'm putting it here for reference. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/queue.h> |
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 <fcntl.h> | |
#include <unistd.h> | |
#include <sys/mman.h> | |
#define RWRR S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH | |
#define MAP_RW PROT_READ | PROT_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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <assert.h> | |
#define BIN_SEARCH(dict, size, needle, res, prefix) \ | |
do { \ | |
assert((dict) != NULL); \ | |
assert((size) > 0); \ | |
int l = 0, r = (size)-1; \ |
OlderNewer