Skip to content

Instantly share code, notes, and snippets.

View thiagomg's full-sized avatar

Thiago Massari Guedes thiagomg

View GitHub Profile

Terminal

Awesome data-driven shell I am using: Nushell

From crago install

  • exa
  • bat
  • broot - tree replacement, but 1000x better
  • du-dust
  • erdtree -> cargo install --git https://github.com/solidiquis/erdtree
int totalize(const std::vector<int> &v, int pos) {
int total = 0;
for(int i=0; i < pos.size(); ++i) {
total += v[i];
}
return total;
}
some_class *get_operation(read_only_conn &db, const std::string &operation_id) {
return new Operation(db.get_operation(operation_id));
}
some_class get_operation(read_only_conn &db, const std::string &operation_id) {
return std::move(db.get_operation(operation_id));
}
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:28
Leitura de configuração em C++
struct my_value {
std::string sval;
using const_iterator = std::string::const_iterator;
};
//...
auto cfg = configuration::load<std::string, my_value>(fname,
[](auto &config, iter_type b, iter_type m, iter_type e) {
std::string k(b, m);
my_value mv;
mv.sval = std::string(m+1, e);
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:25
Leitura de configuração em C++
//Leitura de uma chave
const std::string &log_dir = cfg.get("log.base_dir");
//Agora vamos pegar todas as configurações relativas a log
auto plugins = cfg.prefix("log.");
for(auto p : plugins)
std::cout << p.first << "=>" << p.second << std::endl;
//Lista de plugins na configuração
auto tok = cfg.next_token("plugin.", '.');
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:24
Leitura de configuração em C++
auto after(const Key &prefix) const -> std::unordered_set<Key> {
std::unordered_set<Key> values;
iterate_and_check(prefix, [&values, &prefix](const std::pair<Key,Value> &pair) {
values.insert( pair.first.substr( prefix.size() ) );
});
return values;
}
auto next_token(const Key &prefix, const typename Key::value_type separator) const -> std::unordered_set<Key> {
std::unordered_set<Key> values;
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:23
Leitura de configuração em C++
auto prefix(const Key &prefix) const -> std::vector<map_value> {
std::vector<map_value> values;
iterate_and_check(prefix, [&values](const std::pair<Key,Value> &pair) {
values.push_back(pair);
});
return values;
}
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:21
Leitura de configuração em C++
using adder_func = std::function<void(const std::pair<Key,Value> &pair)>;
void iterate_and_check(const Key &prefix, adder_func f_adder) const {
std::for_each(begin(_items), end(_items), [&prefix, &f_adder](const std::pair<Key,Value> &pair) {
//let's check prefix
if( std::equal( begin(prefix), end(prefix), begin(pair.first) ) )
f_adder(pair);
});
}
@thiagomg
thiagomg / config.h
Created February 4, 2016 22:20
Leitura de configuração em C++
auto get(const Key &key) const -> const Value & {
auto it = _items.find(key);
if( it == _items.end() )
return _empty;
return it->second;
}