Skip to content

Instantly share code, notes, and snippets.

View ajdavis's full-sized avatar

A. Jesse Jiryu Davis ajdavis

View GitHub Profile
@ajdavis
ajdavis / run_in_transaction.c
Last active November 8, 2018 16:21
C examples for single-threaded Sessions API v2 proposal
bool
user_func (mongoc_client_session_t *session,
void *data,
bson_t *reply /* OUT */,
bson_error_t *error /* OUT */)
{
/* the void pointer is used to pass any user data */
user_defined_t *user_data = (user_defined_t *) data;
/* this is just another reference to the same client defined in main(),
digraph gc {
rankdir = LR
label = "ClientSession state transitions. 'insert' stands for any operation.
'error' isn't a permanent state, it just represents throwing an error.
"
labelloc = t
subgraph cluster_autostart {
digraph gc {
rankdir = LR
labelloc = t
label = "ClientSession state transitions. 'insert' stands for any operation.
'error' isn't a permanent state, it just represents throwing an error.
"
subgraph { initial [shape="rectangle"] }
in_progress [label="in progress"]
digraph gc {
rankdir = LR
label = "ClientSession state transitions. 'insert' stands for any operation.
'error' isn't a permanent state, it just represents throwing an error."
labelloc = t
subgraph cluster_autostart {
label = autoStartTransaction
as_initial [label = "initial"]
@ajdavis
ajdavis / # weechat - 2018-01-13_18-43-06.txt
Created January 13, 2018 23:50
weechat on macOS 10.12.6 - Homebrew build logs
Homebrew build logs for weechat on macOS 10.12.6
Build date: 2018-01-13 18:43:06
@ajdavis
ajdavis / insert-many-opts.txt
Last active December 24, 2017 17:05
IDL for C Driver - prototypes
* ``writeConcern``: Construct a :symbol:`mongoc_write_concern_t` and use :symbol:`mongoc_write_concern_append` to add the write concern to ``opts``. See the example code for :symbol:`mongoc_client_write_command_with_opts`.
* ``sessionId``: Construct a :symbol:`mongoc_client_session_t` with :symbol:`mongoc_client_start_session` and use :symbol:`mongoc_client_session_append` to add the session to ``opts``. See the example code for :symbol:`mongoc_client_session_t`.
* ``validate``: Construct a bitwise-or of all desired
`bson_validate_flags_t
<http://mongoc.org/libbson/current/bson_validate_with_error.html>`_. Set to ``0`` to skip client-side validation of the provided BSON documents.
* ``bypassDocumentValidation``: Set to ``true`` to skip server-side schema validation of the provided BSON documents.
* ``collation``: Configure textual comparisons. See :ref:`Setting Collation Order <setting_collation_order>`, and `the MongoDB Manual entry on Collation <https://docs.mongodb.com/manual/reference/collation/>`_.
*
@ajdavis
ajdavis / dnssd.cpp
Created July 28, 2017 18:59 — forked from scaryghost/dnssd.cpp
How to do a SRV or TXT record lookup in C/C++ on Linux.
/**
* compile: g++ -std=c++0x -o dnssd dnssd.cpp -lresolv
* Your g++ compiler must have lambda support
*
* Code based on examples from:
* http://www.cs.columbia.edu/~zwb/project/dotslash/dots_apache/dnsc.c
* http://people.samba.org/bzr/jerry/slag/unix/query-srv.c
*/
#include <arpa/nameser.h>
#include <functional>
@ajdavis
ajdavis / three_eleven_fields.txt
Created March 12, 2017 21:32
Field types file for "mongoimport" to import a CSV from the NYC Open Data set of 311 complaints.
Unique Key.int32()
Created Date.date(01/02/2006 03:04:05 PM)
Closed Date.date(01/02/2006 03:04:05 PM)
Agency.string()
Agency Name.string()
Complaint Type.string()
Descriptor.string()
Location Type.string()
Incident Zip.string()
Incident Address.string()
@ajdavis
ajdavis / strtod-and-nan.md
Last active February 13, 2017 10:42
What is the value of strtod("NaN", NULL) on a sample of platforms?

There are a variety of double values that are not a number, strtod ("NaN", NULL) chooses different values on different platforms. Consider:

#include <stdio.h>
#include <stdlib.h>

int main() {
    union {
        double d;
 unsigned char c[sizeof(double)];
@ajdavis
ajdavis / motor-monitoring.py
Last active January 15, 2019 07:39
Example of MongoDB driver event monitoring with Motor. See https://emptysqua.re/blog/motor-monitoring/
import logging
import sys
import threading
from tornado import ioloop, gen
from motor import MotorClient
from pymongo import monitoring
logging.basicConfig(stream=sys.stdout, level=logging.INFO)