Skip to content

Instantly share code, notes, and snippets.

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

Sergey Lyubka cpq

🎭
Купатися чи не купатись?
View GitHub Profile
const port = 8002;
const http = require('http');
const http_handler = function(req, res) {
let request = '', count = 0;
req.on('data', chunk => request += chunk);
req.on('end', function(ev) {
res.writeHead(200);
const f = function() {
res.write('hi\n');
<!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://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.0/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>
</head>
@cpq
cpq / catcher.js
Created September 15, 2020 12:47
// Run this catcher in a following way:
// 1. Make sure to install tmux, nodejs, and `ws` node package
// apt-get install tmux npm
// npm install -g ws
// 2. Start tmux. This is needed to let the program run after logout.
// When you log in again, `tmux attach` attaches an old session.
// 3. Run catcher in an infinite loop:
// while true; do node catcher.js YOUR_API_KEY ; sleep 1; done
const Websocket = require('ws'); // npm install -g ws
@cpq
cpq / devsim.js
Last active September 11, 2020 20:40
// Simulate mdash.net device. To run this script, install ws library first:
// $ npm -g i ws
// $ node devsim.js MDASH_DEVICE_TOKEN
const Websocket = require('ws'); // npm install -g ws
const pass = process.argv[2]; // Device password
const addr = 'wss://mdash.net/api/v2/rpc?access_token=' + pass;
const ws = new Websocket(addr, {origin: addr});
ws.on('error', msg => console.log(msg.toString()));
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
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);
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);
@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) {
<!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 / 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);