Skip to content

Instantly share code, notes, and snippets.

View mastbaum's full-sized avatar

Andy Mastbaum mastbaum

  • Rutgers University
  • New Brunswick, NJ
View GitHub Profile
@mastbaum
mastbaum / member_function_pointer.cpp
Created January 21, 2012 00:58
A sad, non-working example of a pointer to a non-static member function
#include <iostream>
/* A sad, non-working example of a pointer to a non-static member function */
class Foo {
public:
int threadMe(int a) {
std::cout << "Foo::threadMe: a = " << a << std::endl;
}
};
@mastbaum
mastbaum / static_member_function_pointer.cpp
Created January 21, 2012 00:54
A simple example of a pointer to a static member function
#include <iostream>
/* A simple example of a pointer to a static member function */
class Foo {
public:
static int threadMe(int a) {
std::cout << "Foo::threadMe: a = " << a << std::endl;
}
};
@mastbaum
mastbaum / function_pointer.cpp
Created January 21, 2012 00:38
A simple example of function pointers
#include <iostream>
/** A simple example of function pointers */
// some globally-defined functions that take an int and return an int
int foo(int a) {
std::cout << "foo: a is " << a << std::endl;
return 42;
}
@mastbaum
mastbaum / time_axis.C
Created January 17, 2012 14:50
time axis in root
{
TCanvas* c1 = new TCanvas("c1", "A graph", 200, 10, 700, 500);
// make up some data
const int n = 20;
char label[n][50];
double y[n];
for (int i=0; i<n; i++) {
float xx = i * 0.1;
@mastbaum
mastbaum / number_hack.py
Created September 12, 2011 14:16 — forked from Jach/number_hack.py
Overrides the Python integer five to be equal to four with ctypes magic
import sys
import ctypes
pyint_p = ctypes.POINTER(ctypes.c_byte*sys.getsizeof(5))
five = ctypes.cast(id(5), pyint_p)
print(2 + 2 == 5) # False
five.contents[five.contents[:].index(5)] = 4
print(2 + 2 == 5) # True (must be sufficiently large values of 2 there...)
{
"_id": "some_name",
"source": "source_db_name",
"target": "http://user:password@target_host.com:5984/target_db_name",
"user_ctx": {
"name": "remote_admin_username",
"roles": ["_admin"]
}
}
@mastbaum
mastbaum / gist:1154055
Created August 18, 2011 13:30 — forked from fdmanana/gist:832610
The CouchDB replicator database

1. Introduction to the replicator database

A database where you PUT/POST documents to trigger replications and you DELETE to cancel ongoing replications. These documents have exactly the same content as the JSON objects we used to POST to /_replicate/ (fields "source", "target", "create_target", "continuous", "doc_ids", "filter", "query_params".

Replication documents can have a user defined "_id". Design documents (and _local documents) added to the replicator database are ignored.

The default name of this database is _replicator. The name can be changed in the .ini configuration, section [replicator], parameter db.

2. Basics

@mastbaum
mastbaum / rat_backtrack.cpp
Created August 6, 2011 21:27
Using RAT::TrackNav to find primaries associated with PMT hit photons
#include <iostream>
#include <string>
#include <assert.h>
#include <RAT/DSReader.hh>
#include <RAT/DS/Root.hh>
#include <RAT/TrackNav.hh>
#include <RAT/TrackCursor.hh>
#include <RAT/TrackNode.hh>
@mastbaum
mastbaum / struct_header.c
Created June 21, 2011 16:44
dynamically casting based on a header in a struct
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<string.h>
#include<jemalloc/jemalloc.h>
typedef struct
{
uint32_t type;
} Header;
@mastbaum
mastbaum / struct_malloc_2.c
Created June 17, 2011 18:33
malloc'ing a struct of structs, instance edition
#include<stdio.h>
#include<malloc.h>
typedef struct
{
unsigned long a;
} Bar;
typedef struct
{