Skip to content

Instantly share code, notes, and snippets.

View denisdemaisbr's full-sized avatar

DENIS DOS SANTOS SILVA denisdemaisbr

View GitHub Profile
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.
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.
/*
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
-- 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+
# 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
--! 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
--
-- 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'
/*
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
-- 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
@denisdemaisbr
denisdemaisbr / client-syslog.sh
Last active March 17, 2023 19:32
sample usage of syslog using syslog4j tested with java 1.8 (openjdk version "1.8.0_362")
#!/bin/sh
#
# download package from http://syslog4j.org/
# check also https://manpages.ubuntu.com/manpages/xenial/man1/logger.1.html
#
java -cp syslog4j-0.9.46-bin.jar \
org.productivity.java.syslog4j.server.SyslogServerMain \
-h 127.0.0.1 \
-p 9999 \