Skip to content

Instantly share code, notes, and snippets.

View oakinogundeji's full-sized avatar

'Muyiwa Akin-Ogundeji oakinogundeji

View GitHub Profile
@oakinogundeji
oakinogundeji / connection.js
Created April 13, 2023 11:14
a reliable and robust pattern for connecting to mongodb before starting the app
'use strict';
if(process.env.NODE_ENV != 'production') {
require('dotenv').config();
}
/**
* Module Dependencies
*/
const
Http = require('http'),
Mongoose = require('mongoose'),
0xE56a5289757db606C317342eB1F92C23E650443F
@oakinogundeji
oakinogundeji / vagrant_inventory.js
Created August 30, 2016 19:35
build dynamic ansible inventory from vagrant multi vm
#!/usr/bin/env node
"use strict";
/**
* Run as follows: ansible-playbook -i ./vagrant_inventory.js pbook.yml,
* NB requires the 'vagrant hostsupdater plugin'
*/
//=============================================================================
/**
* Get list of vagrant hosts
*/
@oakinogundeji
oakinogundeji / equi_idx.py
Created August 5, 2016 11:53
Solution to the equilibrium index problem
def soln(A):
sumA, prevSum, n = sum(A), 0, len(A)
for i in xrange(n):
rem = sumA - prevSum - A[i]
if prevSum == rem:
return i
else:
prevSum += A[i]
return -1
@oakinogundeji
oakinogundeji / single_nqueens.py
Last active August 3, 2016 19:00
N - Queens problem: Produces first valid solution.
def nqueens(n):
#This version generates the first valid soln
Q = [None] * n
dfs(0, Q)
print 'ans =', Q
return Q
def dfs(r, Q):
cand_pos, stk = gen_pos(r, Q), []
@oakinogundeji
oakinogundeji / distinct_nqueens.py
Created August 3, 2016 18:55
N - Queens problem: Produces all distinct solutions.
def nqueens(n):
#This version generates all possible solns
seen = set()
for c in xrange(n):
Q = [None] * n
attempt = dfs(0, c, Q)
if attempt:
res = ''
for val in Q:
res += str(val)
@oakinogundeji
oakinogundeji / processors.js
Created April 15, 2016 12:02
Implementing kue as a job queueing solution
/**
*Module dependencies
*/
//-----------------------------------------------------------------------------
var
kue = require('kue'),
config = require('../config/config');
//=============================================================================
/**
*Create 'queue' instance
@oakinogundeji
oakinogundeji / producers.js
Created April 15, 2016 12:01
Implementing kue as a job queueing solution
/**
*Module dependencies
*/
//-----------------------------------------------------------------------------
var
kue = require('kue'),
config = require('../config/config');
//=============================================================================
/**
*Create 'queue' instance
@oakinogundeji
oakinogundeji / processors.js
Created April 15, 2016 11:49
Implementing monq as a job queueing solution
/**
*module dependencies
*/
//-----------------------------------------------------------------------------
var client = require('./producers').client;
//=============================================================================
/**
*create job processor instance
*/
//-----------------------------------------------------------------------------
@oakinogundeji
oakinogundeji / producers.js
Created April 15, 2016 11:48
Implementing monq as a job queueing solution
/**
*Module dependencies
*/
//-----------------------------------------------------------------------------
var
monq = require('monq'),
config = require('../config/config');
//=============================================================================
/**
*Create monq instance