Skip to content

Instantly share code, notes, and snippets.

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

Aruna Tennakoon kakopappa

🏠
Working from home
View GitHub Profile
@kakopappa
kakopappa / name-cheap-dynamic-dns.sh
Created June 3, 2023 04:24 — forked from Goddard/name-cheap-dynamic-dns.sh
auto update ip script for dynamic dns
curl -i -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET https://dynamicdns.park-your-domain.com/update?host=@&domain=[domain]&password=[update-password]&ip=[local-ip]
int ret, len;
mbedtls_net_context listen_fd, client_fd;
unsigned char buf[1024];
const char *pers = "ssl_server";
int port = 443
mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg;
mbedtls_ssl_context ssl;
@kakopappa
kakopappa / esp8266-wifi-connect.ino
Created May 15, 2023 15:58
Example for Arduino ESP8266, ESP32 WiFi connect with max tries
#include <ESP8266WiFi.h>
#define WIFI_SSID "MY SSID"
#define WIFI_PASSWORD "MY PASS"
bool isConnected() {
return (WiFi.status() == WL_CONNECTED);
}
void connectToWiFi(int max_tries = 20, int pause = 500) {
@kakopappa
kakopappa / build_nginx_with_lua.sh
Last active April 8, 2023 09:39 — forked from kanna5/build_nginx_with_lua.sh
A simple script to build nginx with lua support
#!/bin/sh
# Script to build nginx with lua support.
# XXX: The result might work, but it was not thoroughly tested. Use it at your
# own risk. If you really need nginx with LUA in production, you should use
# OpenResty instead.
NGINX_VERSION='1.20.2'
NGX_DEVEL_KIT_VERSION='0.3.1'
@kakopappa
kakopappa / build_nginx_with_lua.sh
Created April 7, 2023 06:07 — forked from riskiwah/build_nginx_with_lua.sh
A simple script to build nginx with lua support
#!/bin/sh
# Script to build nginx with lua support.
NGINX_VERSION='1.18.0'
NGX_DEVEL_KIT_VERSION='0.3.1'
LUA_NGINX_MODULE_VERSION='0.10.16rc5'
STREAM_LUA_NGINX_MODULE_VERSION='0.0.8rc3'
# we use openresty's version of luajit here.
@kakopappa
kakopappa / gist:1d660d7bdf3aae1f76aa40fb1d51a9e3
Last active April 7, 2023 10:38
setup tengine with lua
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev libjemalloc-dev libatomic-ops-dev
sudo apt-get install zlib1g-dev libxslt-dev libgd-dev libgeoip-dev
# build lua
git clone https://github.com/openresty/luajit2
make && make install
export LUAJIT_LIB=/usr/lib64;
export LUAJIT_INC=/usr/include/luajit-2.1;
@kakopappa
kakopappa / uptime.ino
Created January 24, 2023 14:12
ESP32 Uptime example
void setup() {
Serial.begin(115200);
}
void loop() {
char buf[50];
int64_t upTimeUS = esp_timer_get_time(); // in microseconds
int64_t seconds = upTimeUS/1000000;
uint32_t days = (uint32_t)seconds/86400;
uint32_t hr=(uint32_t)seconds % 86400 / 3600;
String encrypt(String plain_data){
int i;
// PKCS#7 Padding (Encryption), Block Size : 16
int len = plain_data.length();
int n_blocks = len / 16 + 1;
uint8_t n_padding = n_blocks * 16 - len;
uint8_t data[n_blocks*16];
memcpy(data, plain_data.c_str(), len);
for(i = len; i < n_blocks * 16; i++){
data[i] = n_padding;
@kakopappa
kakopappa / build-complete.txt
Created September 25, 2021 02:08 — forked from welshstew/build-complete.txt
Generating and using ssl client certificates for use in an nginx sidecar image
[user@localhost certs]$ oc get builds
NAME TYPE FROM STATUS STARTED DURATION
nodejs-mongo-persistent-1 Source Git@e59fe75 Complete About an hour ago 2m37s
simple-nginx-ssl-reverseproxy-1 Source Git@552932f Complete 16 minutes ago 47s
@kakopappa
kakopappa / wait.ino
Last active June 6, 2021 06:33
wait example without delay for esp8266/esp32 from Boris. Blame him if there are bugs
class Wait {
public:
Wait() : next_millis(0) {}
bool operator()(unsigned long wait_millis, bool instant=false) {
unsigned long current_millis = millis();
if (next_millis == 0 && instant==false) next_millis = current_millis + wait_millis;
if (current_millis >= next_millis) {
next_millis = current_millis + wait_millis;
return true;
}