Skip to content

Instantly share code, notes, and snippets.

@andik
andik / cpp_str_split
Created February 23, 2015 13:42
C++ string split
std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
elems.push_back(item);
}
return elems;
}
#include <cstdio>
#include <iostream>
#include <fstream>
#define BUFFER_SIZE 1024
class popen_streambuf : public std::streambuf {
public:
popen_streambuf()
: _fp(NULL)
@andik
andik / gist:c55bb4bc49b54c424935
Created February 23, 2015 12:48
C++ custom iostreams
#include <cstring>
#include <fstream>
using namespace std;
/*** vxor_streambuf class ******************************************/
class vxor_streambuf: public streambuf
{
public:
@andik
andik / gist:aceb338482b790b29c1d
Created February 23, 2015 12:47
popen() example
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
FILE *in;
char buff[512];
if(!(in = popen("ls -sail", "r"))){
@andik
andik / gist:57a317a0545132ab7125
Created February 23, 2015 12:44
Creating a Child Process with Redirected Input and Output in Windows
/*
The example in this topic demonstrates how to create a child process using the CreateProcess function from a console process. It also demonstrates a technique for using anonymous pipes to redirect the child process's standard input and output handles. Note that named pipes can also be used to redirect process I/O.
The CreatePipe function uses the SECURITY_ATTRIBUTES structure to create inheritable handles to the read and write ends of two pipes. The read end of one pipe serves as standard input for the child process, and the write end of the other pipe is the standard output for the child process. These pipe handles are specified in the STARTUPINFO structure, which makes them the standard handles inherited by the child process.
The parent process uses the opposite ends of these two pipes to write to the child process's input and read from the child process's output. As specified in the STARTUPINFO structure, these handles are also inheritable. However, these handles must not be inherited. Therefore, befo
@andik
andik / gist:6595a1ebd8591f555d99
Created February 23, 2015 11:33
OSX Yosemite create Install USB Stick
sudo /Applications/Install\ OS\ X\ Yosemite.app/Contents/Resources/createinstallmedia --volume /Volumes/Stick --applicationpath /Applications/Install\ OS\ X\ Yosemite.app --nointeraction