Skip to content

Instantly share code, notes, and snippets.

@Reselim
Reselim / Buffer.lua
Last active July 29, 2025 06:08
Buffer with string.pack/string.unpack
local function createReadBuffer(data)
local index = 1
local function readRaw(byteCount)
local startIndex = index
index = index + byteCount
local endIndex = index - 1
return string.byte(data, startIndex, endIndex)
end
@santolucito
santolucito / ESP32_UDP_AP.ino
Last active November 29, 2024 01:02
Sending UDP on ESP32 in AP mode
#include <WebServer.h>
#include <WiFi.h>
#include <WiFiUdp.h>
// the IP of the machine to which you send msgs - this should be the correct IP in most cases (see note in python code)
#define CONSOLE_IP "192.168.1.2"
#define CONSOLE_PORT 4210
const char* ssid = "ESP32";
const char* password = "12345678";
WiFiUDP Udp;
@IdrisCytron
IdrisCytron / ESP32WaterFlow.ino
Created October 1, 2019 09:12
Interface water flow sensor with ESP32 board.
/*
Application:
- Interface water flow sensor with ESP32 board.
Board:
- ESP32 Dev Module
https://my.cytron.io/p-node32-lite-wifi-and-bluetooth-development-kit
Sensor:
- G 1/2 Water Flow Sensor
@kassane
kassane / Event_Loop.md
Created April 6, 2019 14:26
Explain Event Loop

Event Loop

In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program.

It works by making a request to some internal or external "event provider" (that generally blocks the request until an event has arrived), and then it calls the relevant event handler ("dispatches the event").

The event-loop may be used in conjunction with a reactor, if the event provider follows the file interface, which can be selected or 'polled' (the Unix system call, not actual polling).

The event loop almost always operates asynchronously with the message originator.

@Gydo194
Gydo194 / Server.cpp
Last active January 6, 2025 09:03
C++ Event driven TCP socket server (multi client, single threaded)
/*
* Server.cpp
*
* EventServer is a simple C++ TCP socket server implementation,
* to serve as an example to anyone who wants to learn it.
* It can interface with the rest of your program using three callback functions.
* - onConnect, which fires when a new client connects. the client's fd is passed.
* - onDisconnect, which fires when a client disconnects. passes fd.
* - onInput, fires when input is received from a client. passes fd and char*
*
@jmjatlanta
jmjatlanta / pub_sub_cpp.cpp
Last active December 23, 2024 05:33 — forked from makomweb/pub_sub_cpp.cpp
Fun with C++: implementing a pub/sub scenario using std::bind and other standard facilities. The approach is pretty similar to the well known .NET event mechanism.
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <memory>
using namespace std;
/***
* A base class for event arguments
@extremecoders-re
extremecoders-re / avr.cfg
Created October 23, 2017 10:51
IDA config file for ATmega328
.ATmega328
; Ida avr.cfg (c) THANATOS
SUBARCH=5
RAM=2048
ROM=32768
EEPROM=1024
; MEMORY MAP
@baymaxium
baymaxium / content.md
Created October 18, 2017 13:01
58速运“里程计算”优化与演进

原文:架构师之路

58速运货物运输,滴滴快递网约车,司机端都是按照行驶公里数收费的,所以“里程”的准确性,是这类业务的一个核心难题,“里程计算”方案演进,以及其中优化思想,是本文要讨论的问题

一、直接调用地图API

这是最容易想到的方法,最省事,但司机往往不是按照预定的路线行驶的,很有可能因为堵车、道路封闭等改变路线,所以直接调用地图API,一次性计算出一个预估值,不太靠谱

优化方案:根据实际路线计算里程

// This function is based on the code found at (the original source doesn't work well)
// http://stackoverflow.com/questions/20774648/three-js-generate-uv-coordinate
//
// She following page explains how UV map should be calculated
// https://solutiondesign.com/blog/-/blogs/webgl-and-three-js-texture-mappi-1/
//
// The following documentation shows what a apherical UV map should look like
// https://threejs.org/examples/#misc_uv_tests
var ThreeUvMapper = {
@eevee
eevee / gist:9cf655e617859d2765f7
Created September 4, 2014 00:40
outline shader for THREE.js
var outline_shader = {
uniforms: {
"linewidth": { type: "f", value: 0.3 },
},
vertex_shader: [
"uniform float linewidth;",
"void main() {",
"vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
"vec4 displacement = vec4( normalize( normalMatrix * normal ) * linewidth, 0.0 ) + mvPosition;",
"gl_Position = projectionMatrix * displacement;",