Skip to content

Instantly share code, notes, and snippets.

View laparca's full-sized avatar

Samuel R. Sevilla laparca

View GitHub Profile
@laparca
laparca / 15puzzle_first_attempt.cpp
Created October 20, 2019 21:26
15puzzle in C++ Metaprogramming
#include <type_traits>
#include <cstdint>
/**
* When an action (structs with its name in lower case), cannot do its operation,
* it returns Nothing.
* All actions returns a 'type'.
*/
struct Nothing {};
@laparca
laparca / monad.hh
Created August 30, 2019 11:50
Simple monad concept in C++
#include <functional>
namespace lzcoders {
namespace MonadHelpers {
template<typename T> struct value_type { using type = typename std::decay<T>::type::value_type; };
template<typename T> using ValueType = typename value_type<T>::type;
struct dummy {
dummy(const dummy&) = default;
dummy(dummy&&) = default;
#!/bin/bash
# Convers a stream of blocks of text into lines. Each line has the whole text of the block.
# For example, for this block
# begin
# some text tha an script put in block
# when we want it in a single line
# because if hard to work with.
# end
# begin
# other interesting text in block
@laparca
laparca / haskell.hs
Last active May 11, 2016 13:54
lazyness
-- for GHCi
let infinite_list = [1..]
let values = filter ((/= 0) . (`mod` 3)) $ filter ((/= 0) . (`mod` 2)) $ map (^2) infinite_list
take 10 values
-- Should be [1,25,49,121,169,289,361,529,625,841]
@laparca
laparca / if.c
Last active August 29, 2015 14:16
Error handling
if (my_function() == ERROR) {
/* do error management */
}
@laparca
laparca / main.c
Created February 11, 2015 12:19
Pseudo lambda for C
#inclued <stdio.h>
/**
* Defines the callback signature
*/
typedef int (*callback_t)(void *);
/**
* Simulates a proccess that inform using a callback
* each time it proccess some data.

Keybase proof

I hereby claim:

  • I am laparca on github.
  • I am laparca (https://keybase.io/laparca) on keybase.
  • I have a public key whose fingerprint is 9E84 26A8 CE88 7C27 64C2 5300 2A8C C58E B6DA 41F5

To claim this, I am signing this object:

@laparca
laparca / test_inject.cpp
Created June 30, 2014 15:03
Proof of Concept of dependency injection in C++
#include <iostream>
#include <string>
#include <map>
#include <typeinfo>
namespace injection {
class instance_generator {
public:
virtual void* get() = 0;
};
OBJS=main.o a.o b.o
all: test_duplicated_structs
clean:
rm test_duplicated_struct $(OBJS) || true
test_duplicated_struct: $(OBJS)
$(CXX) -o $@ $(OBJS) $(LDFLAGS)