Skip to content

Instantly share code, notes, and snippets.

View khaledosman's full-sized avatar
🤘

Khaled Osman khaledosman

🤘
View GitHub Profile
@khaledosman
khaledosman / groupBy.js
Created June 24, 2019 12:27
group an array of objects by a key
const groupBy = (items, key) => items.reduce(
(result, item) => ({
...result,
[item[key]]: [
...(result[item[key]] || []),
item
]
}),
{}
)
@khaledosman
khaledosman / amazon-drs-helpers.js
Last active September 4, 2019 07:35
NodeJS wrapper functions around Amazon Dash Replenishment API
const fetch = require('node-fetch')
const { URLSearchParams } = require('url')
const { dateFromJSON, dateToJSON } = require('../database/utils')
const { User } = require('../database')
const DRS_API_BASE_URL = 'https://dash-replenishment-service-na.amazon.com'
const CLIENT_SECRET = process.env.DRS_CLIENT_SECRET
// const REDIRECT_URL = `${process.env.BASE_URL}/api/amazonLWA`
async function handleErrors (response) {
const json = await response.json()
@khaledosman
khaledosman / csv-helpers.js
Last active August 25, 2021 14:16
helper file to write json data in csv format
function constructCSVFromJSON (json, columns, separator = ',') {
const header = columns.join(separator) + '\n'
let body = ''
if (Array.isArray(json)) {
body = json.reduce((accum, result) => accum + createRowFromJSON(columns, result, separator), '')
} else {
body = createRowFromJSON(columns, json, separator)
}
return header + body
@khaledosman
khaledosman / History|-158cf8bf|entries.json
Last active January 17, 2023 16:38
Visual Studio Code Settings Sync Gist
{"version":1,"resource":"file:///Users/khaledosman/Documents/github/morwins-server/example-response.js","entries":[{"id":"ztZ2.js","source":"textFileCreate.source","timestamp":1651599279809}]}
@khaledosman
khaledosman / mongoose-jobqueue.js
Created April 15, 2019 12:01
mongoose-jobqueue.js
/**
* Mongoose JobQueue Module
* module mongoose-jobqueue
* description A simple jobqueue using [mongoosejs](http://mongoosejs.com).
* This document follows the [JSDocs](http://usejsdoc.org/) markup.
*/
/**
* @typedef {Object} Job
* @property {string} id The unique id of the job.
body {
background: #FFF;
filter: invert(1) hue-rotate(210deg);
}

aws s3 sync s3:// /

S3 Repository

  • Both Local And Remote *
  1. sudo bin/elasticsearch-plugin install repository-s3 (or setup from config / yaml file if docker)
  2. run elastic-search (./bin/elastic)
  3. Create s3 bucket
  4. Create IAM role with access to the s3 bucket and copy his access & secret keys
  5. Add your credentials to elastic search configuration or via config/ elastic-search.yaml file
@khaledosman
khaledosman / remove-ignored-files.sh
Created March 4, 2019 11:00
git ignore not working
git rm -r --cached .
git add .
git commit -m "fixed untracked files"
@khaledosman
khaledosman / gist:4dd514b2b4615176f4853dea33c6308d
Last active February 8, 2019 10:14
Debugging serverless apps
require('inspector').open(9229, "localhost", true)