This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
one simple way to align memory alloc'ed | |
based on sqlite3 macro | |
+7 = 8 (64-bit) | |
+3 = 4 (32-bit) | |
HINT: you can try ptrdiff_t too =) | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void str_replace(void *s, unsigned char target, unsigned char to) { | |
unsigned char* str = (unsigned char*) s; | |
while (*str) { | |
if (*str == target) { | |
*str = to; | |
} | |
str++; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void str_remove(void *s, unsigned char target) { | |
unsigned char* str = (unsigned char*) s; | |
int len = strlen(str); | |
int i, j = 0; | |
for (i = 0; i < len; i++) { | |
if (str[i] != target) { | |
str[j++] = str[i]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/time.h> | |
#include <sys/resource.h> | |
double get_time() | |
{ | |
struct timeval t; | |
struct timezone tzp; | |
gettimeofday(&t, &tzp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function in_array(value, array) | |
for _, v in ipairs(array) do | |
if v == value then | |
return true | |
end | |
end | |
return false | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char* strdup_lower(char* str) { | |
char *b; | |
char *s; | |
char *buf; | |
errno = 0; | |
buf = strdup(str); | |
if (!buf) | |
return NULL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
a simple function to duplicate string and upper it. | |
sample: | |
... | |
char *upper = strdup_upper("HELLO world"); | |
if (!upper) { perror("ops!"); exit(1); } | |
puts(upper); | |
free(upper); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- works like c strstr() | |
-- retorn index if found pattern =) | |
function strstr(haystack, needle) | |
if (not haystack) then return nil; end | |
if (not needle) then return nil; end | |
local h, n = #haystack, #needle; | |
for i = 1, h - n + 1 do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on 2023-05-03-raspios-bullseye-arm64-lite.img.xz | |
# | |
su [your password] | |
apt-get update && sudo apt-get upgrade | |
curl -fsSL test.docker.com -o get-docker.sh && sh get-docker.sh | |
usermod -aG docker [user_name] | |
# fix 'memory/swap' error | |
echo "cgroup_enable=memory swapaccount=1 cgroup_memory=1 cgroup_enable=cpuset" >> /boot/cmdline.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--! lua.org | |
--! get a argument from cli in lua-5.1 | |
if not arg or #arg == 0 then | |
print('lua args.lua [nome]'); | |
os.exit(1); | |
end | |
print( _VERSION ) | |
print( string.format('ola %q', arg[1]) ) |