Skip to content

Instantly share code, notes, and snippets.

Sergey Lyubka cpq

Block or report user

Report or block cpq

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@cpq
cpq / print_linked_list.c
Created Sep 7, 2019
Print singly linked list in reverse order
View print_linked_list.c
#include <stdio.h>
struct entry {
int value;
struct entry *next;
};
static void out(struct entry *e) {
if (e->next != NULL) out(e->next);
printf("%d\n", e->value);
@cpq
cpq / main.c
Created Sep 4, 2019
ESP-IDF mDash skeleton firmware code
View main.c
// Copyright (c) Cesanta Software Limited
// All rights reserved
#include "main.h"
void app_main() {
mDashBegin();
// If a device recovered after a crash, do not start firmware logic
// because it could crash again, thus fall into a crash-loop and make
@cpq
cpq / parser.c
Last active Sep 1, 2019
Simple recursive descent expression parser
View parser.c
// Copyright (c) 2019 Sergey Lyubka
// All rights reserved
#include <stdio.h>
#include <string.h>
enum { TOK_EOF = '#', TOK_NUM = 'N', TOK_IDENT = 'I' };
enum { ERR_OK, ERR_EXPECTED_NUM, ERR_EXPECTED_PAREN };
//#define DEBUG(fmt, ...) printf("%s:" fmt "\n", __func__, __VA_ARGS__)
#define DEBUG(fmt, ...)
View pwa-preact-bulma.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mDash Smart Light</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
@cpq
cpq / preact.html
Last active Jul 16, 2019
minimal preact app with ES3 syntax
View preact.html
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/preact"></script>
</head>
<body> </body>
<script>
var h = preact.h;
var App = function(props) {
View ble.ino
#include <mDash.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#define WIFI_NAME "XX"
#define WIFI_PASS "YY"
#define DEVICE_ID "d1"
View example_mdash_request.js
var https = require('https');
// Same as:
// curl -H 'Content-Type: application-json' -d PARAMS
// https://mdash.net/api/v2/devices/DEVICE_ID/rpc/METHOD?access_token=TOKEN
var mdashRequest = function(apiToken, deviceID, method, params, func) {
return new Promise(function(resolve, reject) {
var received = '';
var strParams = JSON.stringify(params || {});
var url = 'https://mdash.net/api/v2/devices/' + deviceID + '/rpc/' +
@cpq
cpq / bt.sh
Last active May 4, 2019
Symbolizing Arduino backtrace dump for ESP32 (MacOS version)
View bt.sh
#!/bin/sh
# Usage:
# sh bt.sh sketch_Apr25 400d4e36:0x3ffb1e50 0x400d1bce:0x3ffb1e90 0x400d1d96:0x3ffb1ee0 0x400d5a8d:0x3ffb1f30
ARDUINO_DIR=$HOME/Documents/Arduino
A2LINE=$ARDUINO_DIR/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-addr2line
ELF=$(find /var/folders/ -name $INO.elf 2>/dev/null)
INO=$1
shift
@cpq
cpq / rest.js
Created Dec 6, 2018
Minimal REST nodejs server
View rest.js
var http = require('http');
var port = 8080;
var server = http.createServer(function(request, response) {
console.log('Requested URI:', request.url);
response.writeHead(200, {'Content-Type': 'application/json'});
response.write(JSON.stringify({a: 1, b: 2}), 'utf-8');
response.end();
});
server.listen(parseInt(port, 10));
@cpq
cpq / mgos_conf_shadow.c
Created Oct 19, 2018
config via shadow
View mgos_conf_shadow.c
#include "mgos.h"
#include "mgos_rpc.h"
#include "mgos_shadow.h"
static void report_state_to_the_shadow(void) {
const struct mgos_conf_entry *schema =
mgos_conf_find_schema_entry("KEY", mgos_config_schema());
struct mbuf mb;
mbuf_init(&mb, 0);
mgos_conf_emit_cb(&mgos_sys_config, NULL, schema, false, &mb, NULL, NULL);
You can’t perform that action at this time.