Skip to content

Instantly share code, notes, and snippets.

View denisdemaisbr's full-sized avatar

DENIS DOS SANTOS SILVA denisdemaisbr

View GitHub Profile
View bin2hex.c
#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);
View gist:ef376955b606c386ef47b8ef2e2a869e
function in_array(value, array)
for _, v in ipairs(array) do
if v == value then
return true
end
end
return false
end
@denisdemaisbr
denisdemaisbr / strdup_lower.c
Created October 8, 2023 22:26
a simple function to duplicate string and lower it.
View strdup_lower.c
char* strdup_lower(char* str) {
char *b;
char *s;
char *buf;
errno = 0;
buf = strdup(str);
if (!buf)
return NULL;
@denisdemaisbr
denisdemaisbr / strdup_upper.c
Created October 8, 2023 22:23
a simple function to duplicate string and upper it.
View strdup_upper.c
/*
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);
@denisdemaisbr
denisdemaisbr / strstr.lua
Created September 24, 2023 02:01
strstr() lua implementation
View strstr.lua
-- 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
@denisdemaisbr
denisdemaisbr / install.sh
Created August 5, 2023 20:34
how install docker on raspiberry pi 3/3b+
View install.sh
# 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
View gist:ba20927f0e4eb9717efb8250bda82e12
--! 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]) )
@denisdemaisbr
denisdemaisbr / str_split.lua
Last active June 23, 2023 11:26
split a string by length like str_split() from php ported to lua
View str_split.lua
--
-- based on https://www.php.net/manual/en/function.str-split.php
-- feel to free to validate/adjust to uses asserto/error
--
-- Denis Dos Santos Silva
--
local function str_split(str, length)
local result = {}
local index = 1
@denisdemaisbr
denisdemaisbr / rl_helper.php
Created May 27, 2023 13:35
fix Got error 'PHP message: PHP Fatal error: Unparenthesized `a ? b : c ? d : e` is not supported. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in public_html/system/helpers/url_helper.php on line 162'
View rl_helper.php
/*
php -v
PHP 8.0.28 (cli) (built: Feb 14 2023 18:33:29) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.28, Copyright (c) Zend Technologies
with Zend OPcache v8.0.28, Copyright (c), by Zend Technologies
grep CI_VERSION system/core/CodeIgniter.php
define('CI_VERSION', '3.0.0');
*/
@denisdemaisbr
denisdemaisbr / test.sql
Created May 26, 2023 19:49
sqlite3 insert or replace
View test.sql
-- insert or replace sqlite 3.x
create table config( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, key text, value text );
insert into config values (1, "fg", "#ff00ff" );
insert or replace into config(id, key, value) values ((select id from config where key = "bg"), "bg", "0x00ff00");
SELECT * FROM config;
$ sqlite3 < test.sql
SQLite version 3.34.0 2020-12-01 16:14:00
1|fg|#ff00ff