Skip to content

Instantly share code, notes, and snippets.

View Scrappers-glitch's full-sized avatar
🤖
Electrostat Lab.

pavl_g Scrappers-glitch

🤖
Electrostat Lab.
View GitHub Profile
@Scrappers-glitch
Scrappers-glitch / fastboot_help.md
Created January 25, 2023 21:42 — forked from MrHallows/fastboot_help.md
fastboot commands

Command:

$ fastboot help

Output:

usage: fastboot [OPTION...] COMMAND...

flashing:
@Scrappers-glitch
Scrappers-glitch / realloc_example.c
Last active January 26, 2023 21:37
An example showing GNU `realloc`
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main() {
// allocating memory for 6 integers (total = 6 * 4 = 24 bytes)
int* ptr = malloc(6 * sizeof(int));
for (int i = 0; i < 6; i++) { /* 6 * 4 = 24 bytes = 24 * 8 = 192 bits */
@Scrappers-glitch
Scrappers-glitch / passing_params.c
Created January 26, 2023 22:09
Pass by reference V.S. Pass by address
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
static inline void printAddress(void** ptr_address) {
printf("%p\n", *ptr_address);
}
static inline void destroy(void** ptr_address) {
free(*ptr_address);
@Scrappers-glitch
Scrappers-glitch / jni-headers-example.c
Created January 27, 2023 22:40
An example for how java native interface defines its headers and the implementation of java native apis
#include <stdio.h>
#include <stdlib.h>
/**
* Headers
*/
struct JNINativeInterface_ {
void *reserved0;
void *reserved1;
void *reserved2;
@Scrappers-glitch
Scrappers-glitch / techdemo.c
Created January 30, 2023 18:45
Constant pointer to constant data example
#include <stdio.h>
int main(void) {
int x = 8; // define x
int y; // define y
// constant pointer to constant data
const int* const ptr = &x;
printf("%d\n", x);
}
@Scrappers-glitch
Scrappers-glitch / techdemo.c
Created January 30, 2023 18:49
Constant pointer to non-constant data
#include <stdio.h>
int main(void) {
int x = 8; // define x
int y; // define y
// constant location (pointer) to non-constant data
int* const ptr = &x;
// an attempt to modifiy the data will succeed
*ptr = 55;
printf("%d\n", x);
// an attempt to modify the memory location will fail
@Scrappers-glitch
Scrappers-glitch / number_utils_max.c
Created February 13, 2023 15:52
Finds the maximum number among some numbers
#include <stdio.h>
/**
* Finds the maximum number between 2 numbers.
*
* @param n0 the first operand
* @param n1 the second operand
* @return the maximum number, any of the 2 numbers if the numbers are equal
*/
static inline int max0(int n0, int n1) {
@Scrappers-glitch
Scrappers-glitch / private_definition_techdemo.c
Created February 14, 2023 22:33
An example shows a function definition inside another function demonstrating local scopes effect on function definition
#include <stdio.h>
static inline void call_stack() {
void inside_block() {
printf("inside block");
}
inside_block();
}
int main() {
@Scrappers-glitch
Scrappers-glitch / jni_headers_example_2.c
Last active February 15, 2023 20:52
An example showing how to assign a function table to a C struct in one go
#include <stdio.h>
#include <stdlib.h>
/** jni.h **********************************************************************************/
struct JNINativeInterface_ {
void *reserved0;
void *reserved1;
void *reserved2;
void *reserved3;
@Scrappers-glitch
Scrappers-glitch / chunk_cpy.c
Created February 18, 2023 18:15
Tests chunk memory copy in C
/**
* Test chunk memcpy
*
* @author pavl_g
*/
#include <stdio.h>
#include <string.h>
static inline void printAddresses(char* arr, int length) {
for (int i = 0; i < length; i++) {