Skip to content

Instantly share code, notes, and snippets.

Avatar

Evan Klitzke eklitzke

View GitHub Profile
View BUILD
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
cc_binary(
name = "iterperf",
srcs = ["main.cc"],
deps = [
"@benchmark",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/container:node_hash_map",
],
View iterperf.cc
#include "absl/container/flat_hash_map.h"
#include "absl/container/node_hash_map.h"
#include "benchmark/benchmark.h"
#include <map>
#include <unordered_map>
#include <vector>
// std::vector benchmark
View codec.cpp
std::string DecodeBase64(std::string_view input) {
static const uint8_t b64_decode[] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62,
64, 64, 64, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 64, 0,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 64, 64, 64, 64, 64, 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
View solution_16.cpp
#include "cryptopals/aes.h"
#include "cryptopals/answer.h"
#include "cryptopals/block.h"
#include "cryptopals/codec.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
namespace cryptopals {
View codec.cpp
std::string EncodeBase64(std::string_view v) {
size_t sz = v.size();
size_t padding = sz % 3;
if (padding) {
padding = 3 - padding;
}
sz += padding;
ASSERT_DEBUG(sz % 3 == 0);
std::string out(sz * 4 / 3, 0);
View solution11.cc
#include "advent/answer.h"
namespace advent2020 {
namespace {
static const std::vector<std::pair<int, int>> dirs{
{-1, -1}, {-1, 0}, {-1, 1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {0, -1},
};
size_t Neighbors1(const std::vector<std::string> &grid, int i, int j) {
size_t count = 0;
View solution09.cc
#include "advent/answer.h"
#include <numeric>
namespace advent2020 {
void Solution9(std::istream &input, advent::Answer &ans) {
std::vector<uint64_t> nums;
ans.ParseInts(input, nums);
// part1
View gist:7267eb3c0d40e53ffb0b2d9be77dfc14
$ wc -l .bash{rc,_profile} .bash.d/*
49 .bashrc
33 .bash_profile
13 .bash.d/ac.sh
74 .bash.d/aliases.sh
9 .bash.d/bash.sh
174 .bash.d/bazel.sh
4 .bash.d/blog.sh
18 .bash.d/cmake.sh
36 .bash.d/colors.sh
View rightside.cc
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
View zeroes.cc
class Solution {
public:
void moveZeroes(vector<int>& nums) {
auto end = nums.end();
for (auto pos = std::remove(nums.begin(), nums.end(), 0); pos != end; ++pos) {
*pos = 0;
}
}
};