Skip to content

Instantly share code, notes, and snippets.

View christianparpart's full-sized avatar
🎃
Loading

Christian Parpart christianparpart

🎃
Loading
View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@christianparpart
christianparpart / Visitor.hpp
Created November 5, 2018 16:33
some super-generic visitor API
// This file is part of the "klex" project, http://github.com/christianparpart/klex>
// (c) 2018 Christian Parpart <christian@parpart.family>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT
#pragma once
#include <type_traits>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
using namespace std;
template <typename T>
struct Owned { // Requires `T* T::clone() const`
~Owned() = default;
#include <string>
class Blueprint
{
private:
std::string typeName_;
std::string name_;
public:
explicit Blueprint(const std::string& name) : typeName_{"docker"}, name_{name} {}
@christianparpart
christianparpart / cpp-version-of-java-dir-walking.cpp
Last active August 15, 2019 20:43
A small example on how you could code more functional-style in C++ 17/14/11.
// C++17 version of some code shown here in Java:
// https://github.com/impulse-cl/impulse/blob/master/src/main/java/io/impulsecloud/daemon/blueprint/indexer/FileSystemBlueprintIndexer.java#L42
// Since C++ does not provide the convinient API we just implemented it ourselves.
//
// How to compile:
// g++ -std=c++17 demo.cpp -o demo -lstdc++fs
//
// NOTE: This is just for showing what is possible, not for providing the best-possible speed optimized and feature-complete solution.
#include <iostream>
#include <experimental/filesystem>
// trapni@starfall [~] > cat blah.cc
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
// EUID is 0 already (because binary's setuid bit is set and binary's uid=0).
// Now we can use that to set UID to 0.
#include <stdio.h> // printf, getline
#include <stdlib.h> // atoi
char* prompt(const char* msg, char* result, size_t capacity)
{
printf("%s: ", msg);
size_t n = getline(&result, &capacity, stdin);
result[n - 1] = '\0'; // erase linefeed (\n)
return result;
}

Did you know you can checkout pull requests by their number?

git fetch origin pull/<pr_nr>/head:<branch>
git checkout <branch>
@christianparpart
christianparpart / launch.json
Created August 7, 2018 09:52
my Launch.json for Solidity / Visual Studio 2017
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "isoltest.exe (test\\tools\\isoltest.exe)",
"name": "isoltest.exe (test\\tools\\isoltest.exe)",
"currentDir": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}",
#include <thread>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>