Skip to content

Instantly share code, notes, and snippets.

View yasharma's full-sized avatar
🎯
Focusing

Yash Sharma yasharma

🎯
Focusing
View GitHub Profile
@yasharma
yasharma / jolt
Created May 29, 2023 10:59
Twitter v2 jolt transformation
[
{
"operation": "shift",
"spec": {
"data": {
"*": {
"id": "data[&1].id",
"text": "data[&1].text",
"lang": "data[&1].lang",
"created_at": "data[&1].tweet_created_at",
@yasharma
yasharma / hashtags.json
Created December 21, 2022 11:38
Jolt Transformation for twitter trending hashtags data
[
{
"trends": [
{
"name": "#بصره_المهندس_تحييكم",
"url": "http:\/\/twitter.com\/search?q=%23%D8%A8%D8%B5%D8%B1%D9%87_%D8%A7%D9%84%D9%85%D9%87%D9%86%D8%AF%D8%B3_%D8%AA%D8%AD%D9%8A%D9%8A%D9%83%D9%85",
"promoted_content": null,
"query": "%23%D8%A8%D8%B5%D8%B1%D9%87_%D8%A7%D9%84%D9%85%D9%87%D9%86%D8%AF%D8%B3_%D8%AA%D8%AD%D9%8A%D9%8A%D9%83%D9%85",
"tweet_volume": null
},
@yasharma
yasharma / MyLinkedList.js
Last active July 24, 2021 10:00
LinkedList Javascript
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class MyLinkedList {
constructor(value) {
this.head = {
value,
@yasharma
yasharma / db.js
Last active June 4, 2021 10:41
monodb connection
const MongoClient = require('mongodb').MongoClient;
let mongoDB;
const setupDB = callback => {
MongoClient.connect(
process.env.MONGO_DB_URL,
{ useNewUrlParser: true, useUnifiedTopology: true },
(err, _) => {
if (err) {
return callback(err);
@yasharma
yasharma / docker-compose.yml
Last active June 3, 2021 13:10
docker compose
version: "3"
services:
nodejs-kubernetes:
image: local-nodejs-kubernetes
environment:
PORT: 80
MONGO_DB_URL: mongodb://nodejs-kubernetes-mongodb:27017/nodejs-kubernetes
ports:
- 8099:80
depends_on:
FROM node:10.16.3-alpine
LABEL authors="Yash sharma <yashsharma205@gmail.com>"
RUN mkdir /app
WORKDIR /app
COPY ["./package.json", "yarn.lock", "./"]
RUN yarn install
@yasharma
yasharma / index.js
Last active June 4, 2021 10:41
express server
const express = require('express');
const app = express();
const port = process.env.PORT;
const { setupDB } = require('./db');
setupDB((err, success) => {
if(err) throw err;
console.log(success)
const func = (req, res) => {
res.json('Success!')
@yasharma
yasharma / app.js
Created August 19, 2020 11:35
SSE NodeJS and React
useEffect(() => {
const events = new EventSource('http://192.168.1.73:8099/sse');
events.onmessage = (event) => {
console.log(event.data);
};
}, []);
@yasharma
yasharma / setupProxy.js
Created June 11, 2020 10:44
React local proxy API
const proxy = require('http-proxy-middleware')
const devURL = 'https://dev.example.com/'
const uatURL = 'https://uat.example.com/'
const localUrl = 'http://localhost:8099/'
const serverURL = localUrl
const envUrls = {
'/abc': `${serverURL}/abc`,
@yasharma
yasharma / humanizeToDate
Created January 18, 2018 17:28
convert human date to javascript date
function humnizedToDate(date){
var validFormats = ['second','seconds','minute','minutes','hour','hours','day','days','week','weeks','month','months','year','years'];
var _splitDate = date.split(' ');
var findIndex = -1;
_splitDate.forEach(function(val){
if( validFormats.indexOf(val) > -1 ) {
findIndex = validFormats.indexOf(val);
}