Skip to content

Instantly share code, notes, and snippets.

const char HTTPSERVER_GET_REQUEST_TEMPLATE[] PROGMEM =
"GET %s HTTP/1.1\r\n"
"Host: %s\r\n"
"User-Agent: KIOTDevice\r\n"
"Connection: keep-alive\r\n"
"Content-Type: application/json\r\n"
"\r\n";
void _httpGetRaw(String path) {
if (_http_client == NULL) {
bool checkUnreadMessage(bool changeStatusToRead = true, SMSARRAY {Takes a pointer to array of SMS structs} , uint8_t skip = 0,uint8_t limit = 10 ){
sendAT(GF("+CMGL=\"REC UNREAD\","), static_cast<const uint8_t>(!changeStatusToRead));
if (waitResponse(5000L, GF(GSM_NL "+CMGL: \"")) != 1) {
stream.readString();
return {};
}
// read Messages from this
use skip and limit to control what messages to be filled in the sms pointer
// SMSARRAY.push(SMS)
@arihantdaga
arihantdaga / NodejsRaceAndLockDemo.js
Created August 23, 2020 16:41
A simple demonstration of how race conditions can occur in nodeJs and also how to tackle that
let _arr = [];
let count = 0;
class Lock {
constructor() {
this._locked = false;
this._waiting = [];
}
@arihantdaga
arihantdaga / return-promise.js
Created October 22, 2020 17:29
Return or Not Return after resolving/rejecting a promise
let p = new Promise((resolve,reject)=>{
setTimeout(()=>{
resolve("Hello");
console.log("Will I be printed");
}, 2000);
});
p.then(data=>{
console.log(data);
}).catch(err=>{
# Bunch of setting up Steps
pip install transformers[sentencepiece]
pip install sentencepiece
import os
# Load the Pretrained Model
from transformers import AutoTokenizer, AutoModelWithLMHead, PreTrainedModel
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-emotion", use_fast=False)
model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-emotion")
from flask import Flask
from flask import request
app = Flask(__name__)
from mood_tagging import get_emotion
@app.route('/get_emotion', methods=['POST'])
def get_emotion_of_text():
if request.method == 'POST':
text = request.json.get('text')
# base Image
FROM python:3.6-stretch
# install build utilities
RUN apt-get update && \
apt-get install -y gcc make apt-transport-https ca-certificates build-essential git
#Install Pytorch and dependencies
RUN pip3 install torch==1.7.1+cpu torchvision==0.8.2+cpu torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
const char *wifiSSID = "MY_WIFI";
const char *wifiPassword = "MY_PASS";
#define MQTT_HOST "mybroker"
#deinfe MQTT_PORT 1883
#include <ESP8266WiFi.h>
WiFiClient wifiClient;
#include <AsyncMqttClient.h>
AsyncMqttClient mqttClient;
@arihantdaga
arihantdaga / javascript
Created April 26, 2022 08:10
Getting API response with minimum latency
Given an API - /all_data which returns all the schools, all the students and all the books from DB. And return the reponse with minimum possible latency.
And if any of the query fails, returns balnk array for only that entity.
Example -
router.get("/all_data", async (req,res,next)=>{
let schools = await School.find(); // takes 300ms to complete
let students = await Student.find(); // takes 300ms to complete
let books = await Book.find(); // takes 300ms to complete
@arihantdaga
arihantdaga / set_intersection.js
Created September 26, 2022 12:50
Intersection of sets
function getIntersection(setA, setB) {
const intersection = new Set(
[...setA].filter(element => setB.has(element))
);
return intersection;
}
// const set1 = new Set(['a', 'b', 'c']);
// const set2 = new Set(['a', 'b', 'd', 'e']);