Skip to content

Instantly share code, notes, and snippets.

View DavidNexuss's full-sized avatar

David Garcia DavidNexuss

View GitHub Profile
#include <unistd.h>
#include <stdio.h>
/*
My litle contibution to the world of obfuscated code
*/
int main() {
const char* a = "FizzBuzz Fizz BuzzFizz FizzBuzz Fizz 089:>?CGHIMQRVW ";
for(int i = 0; i < (a[0] + ' ') - 1; i++) {
const char* t = a + a[i%15 + 40] - a[40];
/** Debug vector class extended from std vector class for range checking in random access operations
*/
template <typename T>
struct debug_vector : public std::vector<T>
{
debug_vector(size_t size = 0) : std::vector<T>(size) { }
debug_vector(size_t size,const T& fill) : std::vector<T>(size,fill) { }
debug_vector(std::initializer_list<T> values) : std::vector<T>(values) { }
inline const T& operator[](size_t idx) const {
@DavidNexuss
DavidNexuss / super_ptr.hpp
Created February 27, 2021 10:55
Super Pointer
template<typename T>
struct super_ptr: public std::shared_ptr<T>
{
constexpr super_ptr() : std::shared_ptr<T>(new T()) { }
template<typename... Args>
constexpr super_ptr(Args&&... args) : std::shared_ptr<T>(std::make_shared<T>(args...)) { }
constexpr super_ptr(const super_ptr<T>& other) : std::shared_ptr<T>(other) { }
constexpr super_ptr(super_ptr<T>& other) : std::shared_ptr<T>(other) { }
@DavidNexuss
DavidNexuss / fd.hh
Created January 30, 2021 09:08
Smart File Descriptor wrapper for POSIX File Descriptors
#pragma once
#include <unistd.h>
#include <fcntl.h>
#ifdef DEBUG
#include <cstdio>
#endif
class FD
{
int fd;
#include <iostream>
#include <time.h>
using namespace std;
/*
* BinaryTree difined using raw pointers for convenience, so need to pay attention to deallocate memory!*/
struct node
{
int val = 0;
struct node* a = nullptr;
/**
* Made by David Garcia ©, Jutge P9 Repeated words, accepted.
* Tested with Unabomber manifesto, 34k words 0.01s
*/
#include <iostream>
#include <vector>
using namespace std;
int HASH_SIZE;
#STRING="Process runing mem=546M (143%) low mem=2"
STRING="$(heroku logs -n 12 --source heroku -a bullnexmc)"
CUT1=${STRING#*mem=}
CUT2=${CUT1%%)*}
echo "mem=$CUT2)"
echo `expr match "$STRING" '\(.[a-z]\)'`
//Prints all parenthesis combinations of a given lenght using catalan numbers
#include <vector>
#include <iostream>
using namespace std;
struct Node {
int _val;
Node* _father;
vector<Node*> vector;
public class Main {
static interface Func{
float func(float f);
}
public static void main(String[] args) {
Func f = (x)->{return x*x - 4*x*x + 2;};
public class Factorial {
public static void main(String[] args) {
System.out.println(Factorial(5)); //It gives 120
}
//The most beutyful way of calculating the factorial of a number!
public static int Factorial(int i){