Skip to content

Instantly share code, notes, and snippets.

View cpq's full-sized avatar
🎭
Купатися чи не купатись?

Sergey Lyubka cpq

🎭
Купатися чи не купатись?
View GitHub Profile
@cpq
cpq / preact.html
Last active July 16, 2019 14:40
minimal preact app with ES3 syntax
<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) {
<!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 / parser.c
Last active September 1, 2019 18:07
Simple recursive descent expression parser
// 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, ...)
@cpq
cpq / main.c
Last active September 27, 2019 12:05
ESP-IDF mDash skeleton firmware code
// Copyright (c) Cesanta Software Limited
// All rights reserved
#include "main.h"
#define REPORT_FREQUENCY_MS 5000
// This function is called by the main superloop every 10ms.
// We trigger shadow update each REPORT_FREQUENCY_MS milliseconds.
// The other way to do it is to start a dedicated FreeRTOS task.
@cpq
cpq / print_linked_list.c
Created September 7, 2019 14:25
Print singly linked list in reverse order
#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);
<!DOCTYPE html>
<html lang="en">
<head>
<title>hiii</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="https://unpkg.com/bootstrap@4.3.1/dist/css/bootstrap.min.css" />
<script src="https://unpkg.com/preact@8.4.2"></script>
<script src="https://unpkg.com/htm@2.2.1"></script>
@cpq
cpq / read_json.c
Last active November 5, 2019 17:59
char *read_file(const char *path) {
FILE *fp;
char *data = NULL;
if ((fp = fopen(path, "rb")) == NULL) {
} else if (fseek(fp, 0, SEEK_END) != 0) {
fclose(fp);
} else {
size_t size = ftell(fp);
data = (char *) malloc(size + 1);
if (data != NULL) {
const WebSocket = require('ws'); // npm install -g ws
const server = new WebSocket.Server({port: 8000}, function() {
console.log('WS server started');
});
server.on('connection', function connection(ws, req) {
let i = 0;
ws.on('message', function incoming(message) {
console.log('received', message);
});
console.log('connected', req.connection.remoteAddress);
static int BAUD = 115200, RTS = -1, DTR = -1, ESP32_GPIO = 11, ESP32_RESETN = 12;
void setup() {
Serial.begin(baud);
Serial1.begin(baud);
pinMode(ESP32_GPIO0, OUTPUT);
pinMode(ESP32_RESETN, OUTPUT);
// Reset ESP32, put into upload mode
digitalWrite(ESP32_GPIO0, LOW);
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
int character = Serial.read();
if (character == '0') digitalWrite(LED_BUILTIN, LOW); // '0' switches LED off
if (character == '1') digitalWrite(LED_BUILTIN, HIGH); // '1' switches LED on