Skip to content

Instantly share code, notes, and snippets.

View MarcElrick's full-sized avatar
🏠
Working from home

Marc Elrick MarcElrick

🏠
Working from home
View GitHub Profile
@MarcElrick
MarcElrick / folds.md
Last active January 24, 2022 12:33
Explanation of foldl and foldr in haskell with an example

Folds

Folds allow us to use perform iterative operations in Haskell without the need to use loops. We can fold from the left (foldl) or fold from the right (foldr).

foldl

A left fold is fairly simple to comprehend. A left fold takes the form

foldl func acc lst

where:

@MarcElrick
MarcElrick / .bash_aliases
Last active November 2, 2021 14:53
My bash aliases file containing function to switch keyboard layout to US for keychron keyboard only
# Set keyboard layout for keychron board
kc(){
for id in $(xinput list | grep K3 | grep keyboard | cut -d '=' -f 2 | cut -f 1); do setxkbmap -device $id -layout us;done;exit;
}

Data Types and Sizes

There are only a few basic types in C. These are:

Data Type Size
int integers of machine specific size (usually 16 or 32)
double double floating point values
float single floating point values
char single byte ASCII characters

Format Specifiers

Return Type Format Specifier
char %c
int %d
float %f
long %l
double %lf
long double %Lf

Memory Allocation

The following memory allocation functions are all part of <stdlib.h>:

function return type declaration
malloc void * malloc(size_t size)
calloc void * calloc(size_t nitems, size_t size)
realloc void * realloc(void *ptr,size_t size)
free void free(void *ptr)

Pointers, Arrays and Structs

Pointers

The address of a variable in C can be obtained using the & operator and so to find the memory address of a variable var we would use &var.

Similarly, we can use * to 'follow' a pointer through to the variable at said address so if p_var points to var then then we can obtain the value of var using *p_var.

// Assign the value 5 to var.
int var = 5;

Android Rooms

There are 3 main components within rooms:

  • Database
  • Entity
  • DAO - Data Access Objects

Database

The database is an abstract class with the @Database annotation which will extend RoomDatabase. It will include the list of entities associated with the database within the annotation.

Android Notes Part 1 - Android Core

Toasts

A toast is a short message that appears on the screen for a short time period.

// A basic toast can be created as follows:
val text = "Hello toast!"
val duration = Toast.LENGTH_SHORT

val toast = Toast.makeText(applicationContext, text, duration)