Skip to content

Instantly share code, notes, and snippets.

View ReedD's full-sized avatar
🎯
Focusing

Reed Dadoune ReedD

🎯
Focusing
View GitHub Profile
@ReedD
ReedD / alliantSum.js
Last active September 4, 2018 04:09
Sum all transactions since the last statement date.
function sumTransactions(lastStatementDateString) {
const lastStatementDate = new Date(lastStatementDateString);
return [
'ctl00_ctl00_pagePlaceholder_sectionContent_ucTrans_gvPTV',
'ctl00_ctl00_pagePlaceholder_sectionContent_ucPending_gvPending',
]
.map(id =>
Array.from(document.querySelectorAll(`#${id} tr`))
.map(row => {
const columns = Array.from(row.querySelectorAll('td')).map(
@ReedD
ReedD / dragScrollEnd.ts
Created May 26, 2017 04:23
Observable for drag-scroll-end.
import * as Rx from 'rxjs'
const pointerDown$ = Rx.Observable.race(
Rx.Observable.fromEvent(window, 'mousedown'),
Rx.Observable.fromEvent(window, 'touchstart'),
)
const drag$ = pointerDown$.flatMap(() => {
const pointerUp$ = Rx.Observable.race(
Rx.Observable.fromEvent(window, 'mouseup'),
@ReedD
ReedD / docker_to_host.sh
Created February 8, 2017 23:41
Let docker connect to host, output host ip.
#!/bin/bash
iptables -A INPUT -i docker0 -j ACCEPT
# Assumes host has `jq` installed
docker network inspect bridge | jq -r .[0].IPAM.Config[0].Gateway
@ReedD
ReedD / signaler.sh
Created December 16, 2016 18:37
Signal an AWS Auto Scaling Group that an instance has come into service within an ELB.
#!/bin/bash
# Dependencies
# - awscli
# - jq
# Needed IAM permissions
# - elasticloadbalancing:DescribeInstanceHealth
# - elasticloadbalancing:DescribeLoadBalancers
# - autoscaling:DescribeAutoScalingGroups
@ReedD
ReedD / virtual.conf
Created November 9, 2016 17:40
Nginx Reverse Proxy
server {
listen 80;
server_name *.domain.tld;
merge_slashes off;
location / {
proxy_pass http://somealternatedomain.tld;
}
}
@ReedD
ReedD / migrate.js
Created January 7, 2016 20:20
Algorithm to loop through a large MongoDB collection with concurrency support.
'use strict';
var _ = require('lodash'),
async = require('async'),
Bluebird = require('bluebird'),
mongodb = Bluebird.promisifyAll(require('mongodb')),
using = Bluebird.using;
var concurrency = 3;
var totalCount = 0;
@ReedD
ReedD / log.js
Created November 10, 2015 18:05
Helpful node/javascript debug globals
Object.defineProperty(global, '__stack', {
get: function () {
var orig = Error.prepareStackTrace;
Error.prepareStackTrace = function(_, stack){ return stack; };
var err = new Error;
Error.captureStackTrace(err, arguments.callee);
var stack = err.stack;
Error.prepareStackTrace = orig;
return stack;
}
@ReedD
ReedD / EC2_mongodb.sh
Created June 9, 2015 16:11
EC2 MongoDB instance startup command
#!/bin/bash
# http://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
# the following command is the updated version of the command
# used to setup the mongo instance along with the recommended
# EBS volumes
aws --profile <AWS_PROFILE> ec2 run-instances \
--image-id <CURRENT_AWS_LINUX_AMI> \
--instance-type <INSTANCE_TYPE> \
--security-group-ids <SECURITY_GROUP_ID> \
@ReedD
ReedD / luma.js
Created May 22, 2015 18:55
Calculate luma, the lightness of a color between absolute black and the brightest white.
/**
* @name Luma
* @description
* Calculate luma, the lightness of a color between absolute black and the brightest white.
*
* @author Reed Dadoune <reed@dadoune.com>
* @author Alnitak http://stackoverflow.com/a/12043228/3322075
*
* @param {float|string}
* - {float} r The red value of the color
@ReedD
ReedD / ec2-startup.sh
Last active August 1, 2023 17:03
User data for EC2 to set up Docker and Compose (Fig) for ec2-user
#!/bin/sh
export PATH=/usr/local/bin:$PATH;
yum update
yum install docker -y
service docker start
# Docker login notes:
# - For no email, just put one blank space.
# - Also the private repo protocol and version are needed for docker
# to properly setup the .dockercfg file to work with compose