Skip to content

Instantly share code, notes, and snippets.

View mythosil's full-sized avatar

Akito Tabira mythosil

View GitHub Profile
@mythosil
mythosil / crypt_rijndael.pl
Created August 24, 2011 01:35
sample of Crypt::CBC with Rijndael
use strict;
use warnings;
use 5.010;
use Crypt::CBC;
my $cbc = Crypt::CBC->new({
key => 'xxxxxxxxxxxxxxxx',
keysize => 16,
literal_key => 1,
@mythosil
mythosil / http_static.c
Created August 19, 2011 15:02
evhttp returns static files (bug fixed ver.)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <event.h>
#include <evhttp.h>
#define HTTPD_ADDR "0.0.0.0"
#define HTTPD_PORT 8080
@mythosil
mythosil / catty
Created August 19, 2011 06:48
show contents of files with highlight
#!/usr/bin/env perl
use strict;
use warnings;
use Text::VimColor;
my %ft_table = (
pl => 'perl',
cgi => 'perl',
psgi => 'perl',
c => 'c',
@mythosil
mythosil / http_static.c
Created August 18, 2011 17:11
evhttp returns static files
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <event.h>
#include <evhttp.h>
#define HTTPD_ADDR "0.0.0.0"
#define HTTPD_PORT 8080
@mythosil
mythosil / http_plain.c
Created August 18, 2011 15:44
evhttp returns text/plain only
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <event.h>
#include <evhttp.h>
#define HTTPD_ADDR "0.0.0.0"
#define HTTPD_PORT 8080
@mythosil
mythosil / http_notfound.c
Created August 18, 2011 15:16
evhttp returns notfound only
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <event.h>
#include <evhttp.h>
#define HTTPD_ADDR "0.0.0.0"
#define HTTPD_PORT 8080
void req_handler(struct evhttp_request *r, void *arg)
@mythosil
mythosil / echo_server.erl
Created August 12, 2011 08:55
echo server written in erlang
-module(echo_server).
-export([run/0]).
-author('mythosil').
-define(PORT, 1986).
-define(TCP_OPTIONS, [binary, {packet, 0}, {active, false}, {reuseaddr, true}]).
run() ->
Listener = listen(),
accept_loop(Listener).
@mythosil
mythosil / libevent_timer.c
Created August 9, 2011 10:45
libevent sample (timer)
#include <stdio.h>
#include <sys/time.h>
#include <event.h>
void say_hello(int fd, short event, void *arg)
{
printf("Hello\n");
}
int main(int argc, const char* argv[])
@mythosil
mythosil / libevent_test.c
Created August 6, 2011 09:51
libevent sample (echo server)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <event.h>
#define PORT 1986
#define BACKLOG -1
#define BUFSIZE 256
@mythosil
mythosil / fork_echo_server.cpp
Created July 31, 2011 09:12
echo server (fork)
#include <iostream>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
using namespace std;
int setup_listener()
{