Skip to content

Instantly share code, notes, and snippets.

@ackuser
ackuser / gist:ab43242745081d29421800568689d83a
Created May 23, 2016 10:43 — forked from eranation/gist:3241616
MongoDB Aggregation Framework way for "select count (distinct fieldName) from someTable" for large collections
//equivalent of "select count (distinct fieldName) from someTable"
db.someCollection.aggregate([{ $group: { _id: "$fieldName"} },{ $group: { _id: 1, count: { $sum: 1 } } } ])
@ackuser
ackuser / mongodb_distinct_count.js
Created May 23, 2016 10:43 — forked from clarkenheim/mongodb_distinct_count.js
MongoDB equivalent of an SQL query to get the distinct values of a field in a collection including the count of documents which have each distinct value (distinct with count)
//equivalent of MySQL "SELECT COUNT(*) AS `count`, `fieldName` FROM `someTable` GROUP BY `fieldName
db.someCollection.aggregate([{"$group" : {_id:"$fieldName", count:{$sum:1}}}]);
//as above but ordered by the count descending
db.someCollection.aggregate([{"$group" : {_id:"$fieldName", count:{$sum:1}}}, {$sort:{'count':-1}}]);
@ackuser
ackuser / Install-Docker-on-Linux-Mint.sh
Created September 27, 2016 14:18 — forked from sirkkalap/Install-Docker-on-Linux-Mint.sh
Install Docker on Linux Mint
##########################################
# To run:
# curl -sSL https://gist.githubusercontent.com/sirkkalap/e87cd580a47b180a7d32/raw/d9c9ebae4f5cf64eed4676e8aedac265b5a51bfa/Install-Docker-on-Linux-Mint.sh | bash -x
##########################################
# Check that HTTPS transport is available to APT
if [ ! -e /usr/lib/apt/methods/https ]; then
sudo apt-get update
sudo apt-get install -y apt-transport-https
fi
@ackuser
ackuser / AngularJS Provider Test Example
Created October 10, 2016 11:00 — forked from cesarandreu/AngularJS Provider Test Example
Example of how you can test your AngularJS providers.
Look at the README.
@ackuser
ackuser / todo-spec.js
Created October 10, 2016 15:57 — forked from andresdominguez/todo-spec.js
Sample protractor test for todo list in angularjs.org
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('http://www.angularjs.org');
element(by.model('todoText')).sendKeys('write a protractor test');
element(by.css('[value="add"]')).click();
var todoList = element.all(by.repeater('todo in todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write a protractor test');
@ackuser
ackuser / index.html
Created October 18, 2016 08:41 — forked from anonymous/index.html
Crossfilter Examples Jazoon Crossfilter example 1: Dimensions // source http://jsbin.com/biruro
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"
></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js"></script>
@ackuser
ackuser / index.html
Created October 18, 2016 08:41 — forked from anonymous/index.html
Crossfilter Examples Jazoon Crossfilter example 3: Custom reduce functions // source http://jsbin.com/pubaz
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.11/crossfilter.min.js"></script>
@ackuser
ackuser / protractorAPICheatsheet.md
Created October 19, 2016 07:22 — forked from javierarques/protractorAPICheatsheet.md
Protractor API Cheatsheet
@ackuser
ackuser / gist:e6045b4c4e0196aa526b07fc7ef9c949
Created October 27, 2016 11:17 — forked from nherment/gist:1431054
MapReduce with MongoDB in NodeJS
var doMapReduce = function(options, callback) {
var map = function () {
var dateKey = new Date(options.time.getTime());
dateKey.setMinutes(0);
dateKey.setSeconds(0);
dateKey.setMilliseconds(0);
var mapped = {
@ackuser
ackuser / mongodb-singleton.js
Created November 24, 2016 15:01 — forked from afshinm/mongodb-singleton.js
MongoDb singleton connection in NodeJs
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
//the MongoDB connection
var connectionInstance;
module.exports = function(callback) {
//if already we have a connection, don't connect to database again
if (connectionInstance) {
callback(connectionInstance);