Skip to content

Instantly share code, notes, and snippets.

View andrew310's full-sized avatar

Andrew Brown andrew310

View GitHub Profile
from random import randint
from time import sleep
from airflow.contrib.hooks.aws_hook import AwsHook
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
from airflow.utils.decorators import apply_defaults
class AWSGlueCrawlerOperator(BaseOperator):
from random import randint
from time import sleep
from airflow.contrib.hooks.aws_hook import AwsHook
from airflow.exceptions import AirflowException
from airflow.models import BaseOperator
from airflow.utils import apply_defaults
class AWSGlueOperator(BaseOperator):
@andrew310
andrew310 / promise_while_loop.js
Created January 13, 2017 01:18 — forked from victorquinn/promise_while_loop.js
Promise "loop" using the Bluebird library
var Promise = require('bluebird');
var promiseWhile = function(condition, action) {
var resolver = Promise.defer();
var loop = function() {
if (!condition()) return resolver.resolve();
return Promise.cast(action())
.then(loop)
.catch(resolver.reject);
@andrew310
andrew310 / mysql-docker.sh
Created December 5, 2016 06:41 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@andrew310
andrew310 / canSort.js
Created August 3, 2016 22:09
Can Array Be Sorted with One Swap?
function solution(A) {
var newArr = A.slice(); //ceates a copy
newArr.sort( function(a, b){return a-b;});//sort the copy
var counter = 0;
for(var i = 0; i < A.length; i++){ //compare to original
if (newArr[i] != A[i]) counter++;
}
return counter > 2 ? false : true;
}
@andrew310
andrew310 / dedupe.js
Created August 3, 2016 21:52
Deduping Arrays in Javascript
var list = [1, 4, 8, 33, 2, 1, 5, 7, 8, 6, 3, 2];
/*VERSION 1 */
//retains current order of the list
var dups = {}; //create an object, purpose is we want keys
var uniques = list.filter(function(item){
return dups.hasOwnProperty(item) ? false : dups[item] = true;
});
/* How does this work?
@andrew310
andrew310 / bitPermute.js
Last active August 4, 2016 18:36
Permutations of Uppercase and Lowercase Versions of a String
function permute(str){
var len = Math.pow(2, str.length); //possibilities = 2^n
var permutations = [];
for(var i = 0; i < len; i++){
var binaryStr = i.toString(2); //get binary representation
var mask = new Array(binaryStr.length+1).join('0'); //get a string of zeroes
binaryStr = mask.substr(binaryStr.length)+binaryStr; //now we have leading 00's
var permStr = '';
for(j = 0; j < binaryStr.length; j++){