Skip to content

Instantly share code, notes, and snippets.

@IvanIvanoff
IvanIvanoff / numsystems.cpp
Created February 9, 2016 18:26
Converts from dec to other numeral systems
#include <iostream>
#include <assert.h>
const int NUM_SYSTEM = 2;
char arr[] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V','W', 'X','Y', 'Z' };
char* DecToNumSystem(unsigned int num)
{
assert(NUM_SYSTEM > 1);
int size = std::floor(log(num) / log(NUM_SYSTEM)) + 1;
char* res = new char[size];
def handle_cast({:create, name}, names) do
if Map.has_key?(names, name) do
{:noreply, names}
else
{:ok, bucket} = KV.Bucket.start_link
{:noreply, Map.put(names, name, bucket)}
end
end
@IvanIvanoff
IvanIvanoff / mutate.cpp
Created March 16, 2017 09:09
Mutate private data of a class though a pointer of a class with the same memory layout
// Example program
#include <iostream>
#include <string>
class X
{
int x; //private
int y; // private
public:
{What is the capital of Bulgaria?, Sofia,[]}
{What is three times three minus 8, 1,[]}
{Who let the dogs out, who,[]}
{Albania, Tirana, []}
{Andorra, Andorra, []} la Vella
{Armenia, Yerevan, []}
{Austria, Vienna, []}
{Azerbaijan, Baku, []}
{Belarus, Minsk, []}
{Belgium, Brussels, []}
{Bosnia, and, []} Herzegovina Sarajevo
{Bulgaria, Sofia, []}
{Croatia, Zagreb, []}
{What is the capital of Albania?, Tirana, []}
{What is the capital of Andorra?, Andorra, []} la Vella
{What is the capital of Armenia?, Yerevan, []}
{What is the capital of Austria?, Vienna, []}
{What is the capital of Azerbaijan?, Baku, []}
{What is the capital of Belarus?, Minsk, []}
{What is the capital of Belgium?, Brussels, []}
{What is the capital of Bosnia?, and, []} Herzegovina Sarajevo
{What is the capital of Bulgaria?, Sofia, []}
{What is the capital of Croatia?, Zagreb, []}
@IvanIvanoff
IvanIvanoff / pre-commit
Last active October 23, 2022 07:48
pre-commit hook for checking mix formatting
#!/bin/bash
cd `git rev-parse --show-toplevel`
echo "Running pre-commit hook: Check elixir formatting with mix format"
mix format --check-formatted
if [ $? == 1 ]; then
echo "mix format --check-formatted found formatting issues."
exit 1
fi

Keybase proof

I hereby claim:

  • I am ivanivanoff on github.
  • I am ivanivanoff (https://keybase.io/ivanivanoff) on keybase.
  • I have a public key ASACYD-iiQRdWb1-xxvHjzUHw4-lwLroPa9DJpmH2kKmWwo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am ivanivanoff on github.
  • I am ivanivanoff (https://keybase.io/ivanivanoff) on keybase.
  • I have a public key ASACYD-iiQRdWb1-xxvHjzUHw4-lwLroPa9DJpmH2kKmWwo

To claim this, I am signing this object:

@IvanIvanoff
IvanIvanoff / find_path.ex
Last active June 5, 2019 13:51
Search where is located a key-value pair in deeply nested structs
defmodule MapUtils do
def find_pair_path(map, key, value) when is_map(map) do
do_find_pair_path(map, key, value, [])
|> Enum.map(&(&1 |> List.flatten() |> Enum.reverse()))
|> Enum.reject(&(&1 == nil || &1 == []))
end
defp do_find_pair_path(map, key, value, path) when is_map(map) do
keys = Map.keys(map)