Skip to content

Instantly share code, notes, and snippets.

View TheDeveloper's full-sized avatar

TheDeveloper TheDeveloper

View GitHub Profile
@TheDeveloper
TheDeveloper / callback-to-promise.js
Created March 9, 2016 10:43
A little function to convert a callback-style function to Promises
// usage: promisify(function([args..., cb]) { /* do stuff with args then cb */ })()
exports.promisify = function(fn) {
return function(...args) {
return new Promise((resolve, reject) => {
fn(...args, (err, result) => {
if (err) return reject(err);
resolve(result);
});
});
};
@TheDeveloper
TheDeveloper / hmsetx.lua
Created July 21, 2017 10:02
Redis HMSETX script
local key = KEYS[1]
local args = ARGV
local call = redis.call
if call("EXISTS", key) == 0 then
return nil
end
return call("HMSET", key, unpack(args))
@TheDeveloper
TheDeveloper / hmsetex.js
Last active July 24, 2017 17:44
Node module for Redis hmsetex command
/**
* npm install --save lodash redis node-redis-scripty
*
* Usage:
* let hmsetex = require('./hmsetex.js')
* let key = 'your-key';
* let fields = { some_field: 'test', another_field: 'foo' };
* hmsetex(key, fields).then(handleResult).catch(handleError);
*/
const _ = require('lodash');
@TheDeveloper
TheDeveloper / Dockerfile
Created November 13, 2017 17:08
Dockerfile to build Node app image.
FROM mhart/alpine-node:8.9.1
ADD . /app
WORKDIR /app
RUN apk --no-cache add python make gcc g++ git; \
npm install; \
apk --purge del python make gcc g++;
ENTRYPOINT [ "node" ]
@TheDeveloper
TheDeveloper / aws-ship-it-stack.yml
Last active October 15, 2021 16:14
App deploy stack with ECS, CodeBuild & CodePipeline.
# App ship-it stack with ECS, CodeBuild & CodePipeline.
#
# aws cloudformation deploy \
# --stack-name myapp-prod \
# --template-file ./aws-ship-it-stack.yaml \
# --parameter-overrides \
# KeyName=<KEY_NAME> \
# GitHubAuthToken=<ACCESS_TOKEN> \
# RepoOwner=<OWNER_NAME> \
# RepoName=<REPO_NAME> \
@TheDeveloper
TheDeveloper / aws-cluster-stack.yml
Last active February 28, 2024 12:00
Stack to create EC2 instances for ECS cluster.
# Stack to create EC2 instances for ECS cluster.
#
# aws cloudformation deploy \
# --stack-name app-cluster-prod \
# --template-file ./aws-cluster-stack.yaml \
# --parameter-overrides \
# KeyName=DEFAULT \
# SecurityGroups=group1,group2 \
# ImageId=ami-123456 \
# InstanceType=c5.large \
@TheDeveloper
TheDeveloper / buildspec.yml
Created December 18, 2017 15:17
CodeBuild instructions for building a container for a Node.js app.
version: 0.1
phases:
pre_build:
commands:
- $(aws ecr get-login --region $AWS_REGION)
- pip install docker-compose
build:
commands:
- docker build -t $APP_IMAGE .
@TheDeveloper
TheDeveloper / Dockerfile
Created December 18, 2017 16:22
Dockerfile for Node app on ECS.
FROM mhart/alpine-node:8.9.3
ADD . /app
WORKDIR /app
RUN apk --no-cache add python make gcc g++ git; \
npm install; \
apk --purge del python make gcc g++;
CMD [ "node", "src/main" ]
@TheDeveloper
TheDeveloper / docker-compose.yml
Created December 19, 2017 12:25
Docker compose configuration for testing a nodejs app container
test:
image: "${APP_IMAGE}"
links:
- es
- redis
environment:
- NODE_ENV=test
- ES_HOST=es
- REDIS_HOST=redis
@TheDeveloper
TheDeveloper / es-search.js
Created May 3, 2018 11:28
Building up an Elasticsearch query in JS
const secondThing = { term: { field2: 'bar' } };
const firstThing = { term: { field1: 'foo' } };
const filter = [ firstThing, secondThing ];
const bool = { filter };
const query = { bool };
const body = { query };
const params = {
index: 'your-index',
body
};