Skip to content

Instantly share code, notes, and snippets.

View taotetek's full-sized avatar
💭
Left for Gitlab. Microsoft still contracts with ICE.

taotetek taotetek

💭
Left for Gitlab. Microsoft still contracts with ICE.
View GitHub Profile
@taotetek
taotetek / curltest.c
Created May 25, 2016 19:23 — forked from aaronhurt/curltest.c
example code using libcurl and json-c to post and parse a return from http://jsonplaceholder.typicode.com
/**
* example C code using libcurl and json-c
* to post and return a payload using
* http://jsonplaceholder.typicode.com
*
* Requirements:
*
* json-c - https://github.com/json-c/json-c
* libcurl - http://curl.haxx.se/libcurl/c
*
module(
load="imczmq"
servercertpath="/etc/curve.d/server"
clientcertpath="/etc/curve.d/"
authtype="CURVESERVER"
authenticator="on"
)
module(
load="omczmq"
module(
load="imczmq"
authenticator="on"
authtype="CURVESERVER"
clientcertpath="/etc/curve.d/"
servercertpath="/etc/curve.d/server_cert"
)
module(
load="omczmq"
@taotetek
taotetek / channel.c
Created April 25, 2016 14:39
Sharing a thread safe ZMQ_SCATTER socket between multiple threads with inproc transport - very golang channel like. :)
#include <czmq.h>
#include <pthread.h>
#define NUMTHREADS 4
#define MESSAGES 10000000
void *
sender (void *arg)
{
zsock_t *scatter = (zsock_t *) arg;
package main
import (
"fmt"
"log"
"time"
"github.com/zeromq/goczmq"
)
template(name="cee_syslog" type="list") {
constant(value="{\"@timestamp\":\"")
property(name="timereported" dateFormat="rfc3339")
constant(value="\",\"syslog_host\":\"")
property(name="hostname")
constant(value="\",\"syslog_program\":\"")
property(name="programname")
constant(value="\",\"syslog_severity\":\"")
property(name="syslogseverity-text")
constant(value="\",\"syslog_facility\":\"")
func TestExternalServer(t *testing.T) {
client := NewClient(NewSecurityNull())
err := client.Connect("tcp://127.0.0.1:31337")
if err != nil {
t.Error(err)
}
err = client.Send([]byte("HELLO"))
if err != nil {
t.Error(err)
#include "czmq.h"
int
main (void)
{
zsock_t *server = zsock_new (ZMQ_SERVER);
assert (server);
zsock_bind (server, "tcp://127.0.0.1:31337");
char *msg = zstr_recv (server);
printf ("msg: %s", msg);
package captainslog
import "sync"
type Queue struct {
q []SyslogMsg
lock *sync.Mutex
}
func NewQueue(max int) *Queue {
package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"net"
"os"
"strings"