Skip to content

Instantly share code, notes, and snippets.

View Scrappers-glitch's full-sized avatar
🤖
Software~Hardware Co-Desgin

pavl_g Scrappers-glitch

🤖
Software~Hardware Co-Desgin
View GitHub Profile
@Scrappers-glitch
Scrappers-glitch / free_buffer_cells.c
Created September 19, 2023 22:24
Example for freeing buffer cells of a pointer to a pointer
// Online C compiler to run C program online
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static inline void freeBufferCells(void** buffer, int count) {
for (int i = 0; i < count; i++) {
free(buffer[i]);
buffer[i] = NULL;
}
git rm -r --cached .
git add .
git commit -m "fixing .gitignore"
@Scrappers-glitch
Scrappers-glitch / Disassemble.as
Created April 24, 2023 19:29
Disassemble code
└──╼ $./avr-objdump -S '/home/twisted/GradleProjects/ShiftAvr/shiftavr-examples/build/atmega328p/hello_gpio_write.c.elf'
/home/twisted/GradleProjects/ShiftAvr/shiftavr-examples/build/atmega328p/hello_gpio_write.c.elf: file format elf32-avr
Disassembly of section .text:
00000000 <__vectors>:
0: 0c 94 34 00 jmp 0x68 ; 0x68 <__ctors_end>
4: 0c 94 46 00 jmp 0x8c ; 0x8c <__bad_interrupt>
@Scrappers-glitch
Scrappers-glitch / Wrapper.java
Last active April 8, 2023 09:18
Generics in java
public class Wrapper {
private Object object;
public Wrapper(Object object) {
this.object = object;
}
public void setObject(Object object) {
this.object = object;
}
import java.util.ArrayList;
class TestSuperCapture {
static class TestSuper {}
static class TestSub extends TestSuper {}
static class TestSub2 extends TestSub {}
static class TestSub3 extends TestSub2 {}
public static void main(String[] args) {
@Scrappers-glitch
Scrappers-glitch / jlong_implement.c
Last active March 27, 2023 23:23
Test void* to jlong implicit type-conversion.
#include <stdio.h>
#include <stdlib.h>
/* define a non-system-specific pointer type that can hold an address of up-to 8-bytes */
typedef long long jlong;
jlong Java_util_getAddress() {
int* x = malloc(sizeof(int));
*x = 2312;
void* address = x;
@Scrappers-glitch
Scrappers-glitch / star_matrix.c
Last active March 7, 2023 23:58
Tests a clean way of printing star matrices
#include <stdio.h>
/** Header file */
typedef struct {
int rows;
int columns;
} StarMatrixMetadata;
void print_star_matrix(StarMatrixMetadata metadata);
@Scrappers-glitch
Scrappers-glitch / credentials_references.c
Created March 7, 2023 22:34
Tests multi-dimensional references using a pointer to an array of strings.
#include <stdio.h>
int main(void*) {
const char* user = "Andrew";
const char* passwd = "ZirqfRopWpedsS0012#24";
/* create a pointer to strings (notice, we are just creating references here) */
const char* credentials[] = {user,
passwd};
/* get an element from the 1st dimension */
@Scrappers-glitch
Scrappers-glitch / credentials_buffer.c
Created March 7, 2023 22:31
Tests Multi-dimensional arrays and accessing memory chunks using pointers
#include <stdio.h>
int main(void*) {
/* create an array of strings (arrays of characters) */
/* This buffer is allocated in contigous memory chunks */
const char credentials[][255] = {"Andrew",
"ZirqfRopWpedsS0012#24"};
/* get an element from the 1st dimension */
const char* user_cred = credentials[0]; /* or use *(credentials + 0) */
@Scrappers-glitch
Scrappers-glitch / sqmat_add.c
Last active March 4, 2023 11:14
Example showing matrix addition in c
#include <stdio.h>
#include <stdlib.h>
int* mat_add(int*, int*, int);
int* mat_add(int* a, int* b, int enteries) {
// enteries * 4 = 2 * 4 = 8 bytes
int* summation = (int*) calloc(enteries, sizeof(int));
for (int row = 0; row < enteries; row++) {
for (int column = 0; column < enteries; column++) {