Skip to content

Instantly share code, notes, and snippets.

View alperg's full-sized avatar

Alper Gokcehan alperg

  • RTP, NC, United States
View GitHub Profile
@alperg
alperg / sortObjectIntoArray.js
Created December 19, 2022 15:14 — forked from armenic/sortObjectIntoArray.js
JavaScript Sort Object by Values Into Array of Objects
import assert from "assert";
function main() {
let obj = {
big: 4,
biggest: 6,
bigger: 5,
small: 1,
};
@alperg
alperg / mock-mongoose-model.js
Created May 1, 2017 19:06 — forked from dylants/mock-mongoose-model.js
When testing code which uses Mongoose models, you often run into problems when the schemas are not defined. This code provides an idea on how to mock these models (in a `beforeEach`) and clear them later (in an `afterEach`)
"use strict";
var mongoose = require("mongoose");
var mockMongooseModel = {};
module.exports = mockMongooseModel;
/**
* This function is useful for tests that require Mongoose models
* loaded prior to loading the test file. This should be called in
@alperg
alperg / app.js
Created May 1, 2017 19:05 — forked from dylants/app.js
Passport security using local authentication (username/password)
require("express-namespace");
var express = require("express"),
fs = require("fs"),
cons = require("consolidate"),
app = express(),
passport = require("passport"),
mongoose = require("mongoose");
// 30 days for session cookie lifetime
var SESSION_COOKIE_LIFETIME = 1000 * 60 * 60 * 24 * 30;
@alperg
alperg / README.md
Created March 22, 2016 12:31 — forked from rvillars/README.md
Preprocess directive attributes in AngularJS

Preprocess directive attributes in AngularJS

Sometimes you need to modify a two way binded attribute value prior to use it in the directive. This can't be done in the directive controller, because the attribute assignment is done after the controller is executed.

The link function is able to access the attributes directly but unfortunately a two way binded attribute expression isn't yet evaluated a that time.

The solution is to process the attribute in a scope.$watch function where the value will be evaluated automatically.

http://jsfiddle.net/gh/gist/angularjs/1.2.1/d60d9416f2206c6e3407/