Skip to content

Instantly share code, notes, and snippets.

@TvdW
TvdW / gist:1073158
Created July 9, 2011 00:55
Sample C++ memory object
class Object {
public:
int retainCount;
void alloc();
virtual void dealloc();
void release();
void retain();
};
@TvdW
TvdW / gist:1073174
Created July 9, 2011 01:13
C++ memory object extending
class Sheep : Object {
void makeNoise();
};
int main() {
Sheep* sheep = new Sheep; // it is automatically retained once.
// Do stuff with the sheep
sheep.release(); // it is deallocated
// In the header file
@property (retain) NSObject *obj;
// In the code
-(id)init {
// WRONG: obj = [[NSData alloc] init]; // This won't call [obj retain]; !!!!
[self setObj:[[NSData alloc] init]]; // CORRECT: [obj retain]; is called properly
return self;
}
@TvdW
TvdW / gist:3732203
Created September 16, 2012 12:22
JSON string encoder, from STL string to JSON
static inline std::string jsonEscape(std::string &str)
{
std::string escaped = "\"";
char buf[16];
unsigned int i;
for (i = 0; i < str.size(); i++)
{
if (str[i] == 34) escaped += '\\';

Keybase proof

I hereby claim:

  • I am tvdw on github.
  • I am tvdw (https://keybase.io/tvdw) on keybase.
  • I have a public key whose fingerprint is D6F9 F239 E0C9 D283 5D3D E267 2DB3 6243 CF38 B160

To claim this, I am signing this object:

#include <string.h>
#include <curl/curl.h>
fd_set wfds;
fd_set rfds;
struct timeval tv;
int maxfd = 0;
int socket_callback(CURL *easy, /* easy handle */
curl_socket_t s, /* socket */
#include <string.h>
#include <assert.h>
#include <curl/curl.h>
fd_set wfds;
fd_set rfds;
struct timeval tv;
int maxfd = 0;
int socket_callback(CURL *easy, /* easy handle */
#include <string.h>
#include <curl/curl.h>
fd_set wfds;
fd_set rfds;
struct timeval tv;
int maxfd = 0;
int socket_callback(CURL *easy, /* easy handle */
curl_socket_t s, /* socket */
#include "curl/curl.h"
int main(int argc, char** argv)
{
CURLM *multi = curl_multi_init();
curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
curl_multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS, 4);
int j;
for (j = 0; j < 100; j++) {
#include <string.h>
#include <curl/curl.h>
fd_set wfds;
fd_set rfds;
struct timeval tv;
int maxfd = 0;
int socket_callback(CURL *easy, /* easy handle */
curl_socket_t s, /* socket */