Skip to content

Instantly share code, notes, and snippets.

@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
@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: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: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:
#include <cstdio>
#include <iostream>
#include <fstream>
#define BUFFER_SIZE 1024
class popen_streambuf : public std::streambuf {
public:
popen_streambuf()
: _fp(NULL)
@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;
}
@andik
andik / FuzzyMatch.js
Created March 6, 2015 07:56
Fuzzy matching
function fuzzy_match(text, search)
{
/*
Parameter text is a title, search is the user's search
*/
// remove spaces, lower case the search so the search
// is case insensitive
var search = search.replace(/\ /g, '').toLowerCase();
var tokens = [];
var search_position = 0;
@andik
andik / app.py
Created March 18, 2015 15:38
serve static files from flask
from flask import Flask, request, send_from_directory
# set the project root directory as the static folder, you can set others.
app = Flask(__name__, static_url_path='')
@app.route('/js/<path:path>')
def send_js(path):
return send_from_directory('js', path)
if __name__ == "__main__":
@andik
andik / various.hpp
Created March 18, 2015 22:17
C++ PP List and PP Typelists
#define List(o) \
o(1,2) \
o(2,3) \
#define MAP_CALL_FN_PARENS(...) (__VA_ARGS__);
#define MAP_CALL_FN(fn) fn MAP_CALL_FN_PARENS
#define MAP(list, fn, ...) list(MAP_CALL_FN(fn))
@andik
andik / filebrowser.js
Created March 23, 2015 12:20
tinymce file browser
tinymce.init({
file_browser_callback: function(field_name, url, type, win) {
tinymce.activeEditor.windowManager.open({
title: "My file browser",
url: "myfilebrowser.html",
width: 800,
height: 600
}, {
oninsert: function(url) {
win.document.getElementById(field_name).value = url;