Skip to content

Instantly share code, notes, and snippets.

View adventurist's full-sized avatar

Emmanuel Buckshi adventurist

View GitHub Profile
@adventurist
adventurist / poll_test.cpp
Created August 18, 2020 01:14
poll forked process
struct ProcessResult {
std::string output;
bool error = false;
};
ProcessResult run(std::vector<std::string> args) {
int stdout_fds[2], stderr_fds[2];
pipe(stdout_fds);
pipe(stderr_fds);
#include <sys/wait.h>
#include <unistd.h>
#include <sys/epoll.h>
#include <string>
#include <vector>
struct ProcessResult {
std::string output;
bool error = false;
};
@adventurist
adventurist / decoder.asm
Created July 7, 2020 19:05
Decoder getter (asm)
Decoder::Decoder() [base object constructor]:
push rbp
push rbx
mov rbx, rdi
sub rsp, 24
mov QWORD PTR [rdi], 0
mov QWORD PTR [rdi+8], 0
mov QWORD PTR [rdi+16], 0
mov edi, 4990
call operator new(unsigned long)
@adventurist
adventurist / decoder.cpp
Created July 7, 2020 19:03
Decoder getter (cpp)
#include <memory>
#include <vector>
class Decoder {
public:
Decoder() { buffer.reserve(4990);}
bool decode(unsigned char* data, uint32_t size) {
if (size == 10) {
buffer.insert(buffer.end(), data, data + size);
@adventurist
adventurist / decoder.asm
Created July 7, 2020 18:55
Decoder shared_ptr (asm)
Link::~Link() [base object destructor]:
push r12
mov r12, rdi
push rbp
push rbx
mov rbx, QWORD PTR [rdi+24]
test rbx, rbx
je .L3
mov ebp, OFFSET FLAT:_ZL28__gthrw___pthread_key_createPjPFvPvE
lea rax, [rbx+8]
@adventurist
adventurist / decoder.cpp
Created July 7, 2020 18:54
Decoder shared_ptr (cpp)
#include <memory>
#include <vector>
class Decoder {
public:
void init(std::shared_ptr<std::vector<unsigned char>> s_buffer) {
buffer = s_buffer;
}
void decode(unsigned char* data, uint32_t size) {
@adventurist
adventurist / decoder.asm
Created July 7, 2020 18:53
Decoder returns vector (asm)
Decoder::Decoder() [base object constructor]:
push rbp
push rbx
mov rbx, rdi
sub rsp, 24
mov QWORD PTR [rdi], 0
mov QWORD PTR [rdi+8], 0
mov QWORD PTR [rdi+16], 0
mov edi, 4990
call operator new(unsigned long)
@adventurist
adventurist / decoder.cpp
Created July 7, 2020 18:51
Decoder returns vector (cpp)
#include <memory>
#include <vector>
class Decoder {
public:
Decoder() { buffer.reserve(4990);}
std::vector<unsigned char> decode(unsigned char* data, uint32_t size) {
if (size == 10) {
buffer.insert(buffer.end(), data, data + size);
@adventurist
adventurist / button_led.c
Last active April 7, 2020 04:21
Arduino circuit with tactile button and 10kohm resistor to control build-in LED
#include <avr/io.h>
#include <stdio.h>
#include <util/delay.h>
int main(void) {
DDRB = 0xFF; // set all pins on PORTB to output
DDRD &= ~(1 << 1); // set pin 2 on PORTD to input
for (;;) {
if ((PIND & (1 << 1))) { // if 2nd bit set on PIND
PORTB |= (1 << 5); // turn on LED
#include <cstdio>
#include <type_traits>
#include <utility>
#define First(x) std::get<0>(x)
#define Second(x) std::get<1>(x)
template <typename T>
class GeoCoordinate {
typedef std::pair<T, T> CoordPair;