Skip to content

Instantly share code, notes, and snippets.

View michaelbacci's full-sized avatar

Michael michaelbacci

View GitHub Profile
@michaelbacci
michaelbacci / token_git.md
Last active November 16, 2023 16:14
Adding token for automatic authentication for gitlab, github, etc...
echo 'https://{user}:{token}@your_git_url' > ~/.git-credentials && git config --global credential.helper store
/*
Here two solutions for this problem:
Consider an array of numeric strings where each string is a positive number with anywhere from to digits.
Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array.
Example ['1', '200', '150', '3']
Return the array ['1', '3', '150', '200'].
*/
void countApplesAndOranges(int s, int t, int a, int b, vector<int> apples, vector<int> oranges) {
std::transform(apples.begin(), apples.end(),apples.begin(), [a](auto x) {
return a + x;
});
std::transform(oranges.begin(), oranges.end(),oranges.begin(), [b](auto x) {
return b + x;
});
std::cout << std::count_if(apples.begin(), apples.end(), [s, t](auto x) {
return s <= x && x <= t;
}) << std::endl
vector<int> gradingStudents(vector<int> grades) {
std::transform(grades.begin(), grades.end(), grades.begin(), [](auto x) {
if (x < 38) return x;
if (auto d = x % 5; 5 - d < 3) {
return x + 5 - d;
}
return x;
});
return grades;
}
#include <bits/stdc++.h>
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);
struct hash_tuple {
template <class T1, class T2>
#include <bits/stdc++.h>
using namespace std;
string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);
/*
* Complete the 'zeroMoveNim' function below.
@michaelbacci
michaelbacci / bimap.go
Created June 7, 2023 15:15
Simple bidirectional map in golang
type KeyType string
type ValueType int
type BiMap struct {
forward map[KeyType]ValueType
backward map[ValueType]KeyType
}
func NewBiMap() *BiMap {
return &BiMap{
@michaelbacci
michaelbacci / xsimd_containers.cpp
Last active June 17, 2021 13:59
xsimd with generic container type
/**
* @bref Example of how the use of xsimd could be generalized to handle containers like std::vector and xt::xarray.
* @link https://xsimd.readthedocs.io/en/latest/vectorized_code.html#memory-alignment-and-tag-dispatching
*/
#include <cstddef>
#include <vector>
#include <xsimd/xsimd.hpp>
#include <xtensor/xarray.hpp>
#include <xtensor/xmath.hpp>
@michaelbacci
michaelbacci / osx_fix_gdb_certificate_permission.md
Created May 3, 2021 21:18
please check gdb is codesigned - see taskgated(8)

Fix gdb error access for macOS Catalina

  1. Open keychain Access.App > Certificate Assistant > Create Certificate with Self Signed Root then set full priviledges to certificate.

  2. Open terminal and paste:

cat <<EOF > gdb.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
@michaelbacci
michaelbacci / forward_or_transform.cxx
Last active February 16, 2021 16:24
C++ forward_or_transform. e.g: use std::string within printf
namespace io {
template <class X>
using is_string = typename std::enable_if<std::is_same<X, std::string>::value>::type;
template <class X>
using is_not_string = typename std::enable_if<!std::is_same<X, std::string>::value>::type;
template <class T, class = is_not_string<T>>
constexpr T forward_or_transform(T t) {
return std::forward<T>(t);