Skip to content

Instantly share code, notes, and snippets.

View sdgluck's full-sized avatar

Sam Gluck sdgluck

View GitHub Profile
@sdgluck
sdgluck / query.js
Last active April 23, 2024 17:48
Pagination using Mongo: populate, match, sort, count, and limit with the aggregation pipeline
/**
* Query blog posts by user -> paginated results and a total count.
* @param userId {ObjectId} ID of user to retrieve blog posts for
* @param startRow {Number} First row to return in results
* @param endRow {Number} Last row to return in results
* @param [filter] {Object} Optional extra matching query object
* @param [sort] {Object} Optional sort query object
* @returns {Object} Object -> `{ rows, count }`
*/
function queryBlogPostsByUser (userId, startRow, endRow, filter = {}, sort = false) {

Keybase proof

I hereby claim:

  • I am sdgluck on github.
  • I am sdgluck (https://keybase.io/sdgluck) on keybase.
  • I have a public key whose fingerprint is BD99 05F8 A03C 6849 2712 EBA9 7714 4CC1 8FF5 819F

To claim this, I am signing this object:

@sdgluck
sdgluck / breakpoint-mixins.scss
Created September 19, 2016 15:15
SCSS breakpoint mixins
@mixin tiny {
@at-root {
@media screen and (max-width: 480px) {
@content;
}
}
}
@mixin mobile {
@at-root {
@sdgluck
sdgluck / ag-date-filter.js
Last active January 1, 2017 17:39
Simple HTML5 date filter for ag-grid. Requires: moment.js
'use strict';
var moment = require('moment');
var template = '' +
'<div class="ag-date-custom-filter">' +
' <select ng-model="queryType">' +
' <option value="exact">Exact</option>' +
' <option value="between">Between</option>' +
' </select>' +
@sdgluck
sdgluck / dropCollection.js
Last active August 14, 2016 17:03
Drop a collection with mongoose and remove internal references. Returns a Promise.
function dropCollection (modelName) {
if (!modelName || !modelName.length) {
Promise.reject(new Error('You must provide the name of a model.'));
}
try {
var model = mongoose.model(modelName);
var collection = mongoose.connection.collections[model.collection.collectionName];
} catch (err) {
return Promise.reject(err);
@sdgluck
sdgluck / font-size.mixin.less
Last active November 4, 2015 14:37
LESS rem font-size mixin with px fallback. Requires that html, body has font-size: 62.5% such that 1rem = 10px.
.font-size (@size) {
@px: @size * 10;
font-size: e("@{px}px");
font-size: e("@{size}rem");
}
@sdgluck
sdgluck / angular.element.doAnim.js
Last active June 3, 2017 09:30
An extension of Angular's angular.element prototype with method doAnim; a function to invoke CSS animations.
/**
* Invoke a CSS animation on `this` angular.element instance.
* @param className classname of animation to invoke on `this` element
* @param delay delay before animation is invoked
* @param done callback
*/
angular.element.prototype.doAnim = function(className, delay, done, doneDelay) {
done = (typeof delay === 'function') ? delay : done;
$timeout(function() {
this.removeClass(className);