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 / AppModel.php
Last active February 18, 2016 07:32
A CakePHP model function to find and sort by the distance from a given a latitude and longitude coordinate with the option to restrict to a given radius.
<?php
App::uses('Model', 'Model');
App::uses('String', 'Utility');
class AppModel extends Model {
/**
* @author Reed Dadoune
* distanceQuery
@ReedD
ReedD / index.js
Created April 29, 2014 18:07
AngularJS - Cancel http request before completion.
var canceler = $q.defer();
$http.get('/someUrl', {timeout: canceler.promise}).success(successCallback);
// later...
canceler.resolve(); // Aborts the $http request if it isn't finished.
@ReedD
ReedD / delay.js
Created May 15, 2014 17:49
A function wrapper to repeatedly delay a given JavaScript function
/**
* A function wrapper to repeatedly delay a given function
* Example:
*
* // Generic usage
* delay(function () {
* console.log('1 second delay');
* }, 1000);
*
* // Namespaced delay
@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
@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_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 / 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 / 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 / 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 / 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