Skip to content

Instantly share code, notes, and snippets.

View Silva97's full-sized avatar
🤔
Thinking, of course.

Luiz Felipe Silva Silva97

🤔
Thinking, of course.
View GitHub Profile
@Silva97
Silva97 / Sum - Silva97.yaml
Created October 24, 2020 03:19
Turing Machine code for sum numbers | Just a test :)
name: Sum - Silva97
source code: |-
input: '0010+0011'
blank: ' '
start state: look
table:
left4:
0: {L: left3}
1: {L: left3}
'+': {L: left3}
#include <stdio.h>
// Example of code in C to get substrings
char *substr(char *dest, char *src, int start, int end)
{
char *start_address = dest;
for (src = src + start; *src && end > 0; dest++, src++, end--) {
*dest = *src;
}
@Silva97
Silva97 / benchmark_smaller_branchless.c
Created July 8, 2020 16:57
Teste de benchmark de um exemplo de código branchless para verificar qual número é menor
#include <stdio.h>
#include <stdlib.h>
#include "metric.h" // https://github.com/Silva97/metric
int smaller(int a, int b)
{
if (a < b) {
return a;
}
@Silva97
Silva97 / rfc1071.asm
Created June 23, 2020 01:28
Implementação do algoritmo de checksum RFC 1071 em Assembly x86-64
; Implementação do algoritmo de checksum RFC 1071 em Assembly x86-64.
; Exercício proposto pelo Frederico Pissarra.
bits 64
default rel
section .text
; unsigned short cksum( void *ptr, size_t size );
; Entrada: RDI = ptr
#include <stdio.h>
#include <unistd.h>
enum {
READ = 0,
WRITE,
};
int main(void)
{
@Silva97
Silva97 / index.html
Last active June 12, 2020 18:56
Observer in JS
<!DOCTYPE html>
<html>
<head>
<title>Observer</title>
<script src="./main.js"></script>
<style>
.list {
display: flex;
flex-direction: column;
// Exemplo de impressão de caracteres Unicode em C.
#include <stdio.h>
#include <locale.h>
#include <wchar.h>
int main(void)
{
wchar_t str[] = L"Oi ✌ cara! €€€";
setlocale(LC_CTYPE, "pt_BR.utf8");
#include <stdio.h>
#include <stdlib.h>
int cmpfloat(const void *n1, const void *n2)
{
return *( (const float *) n1 ) > *( (const float *) n2 );
}
#define SIZE 3
#include <stdio.h>
#include <stdlib.h>
void triangle(int, int);
int main(int argc, char **argv)
{
triangle(atoi(argv[1]), 0); // 17
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#define ASIZE 4
int main(void)
{
// char *a[ASIZE];
char **a = malloc(sizeof (char *) * ASIZE);
for (int i = 0; i < ASIZE; i++)