Skip to content

Instantly share code, notes, and snippets.

View srfrnk's full-sized avatar
:octocat:
prancing about

Srfrnk srfrnk

:octocat:
prancing about
View GitHub Profile
@srfrnk
srfrnk / backToTop.js
Last active August 29, 2015 13:56
angular directive to add a fixed floater that scrolls page to top. appears only when scrolled down.
app.directive("backToTop", ["$window", function ($window) {
return {
restrict: 'E',
transclude: true,
template: '<div class="back-to-top"><style>' +
'.back-to-top {' +
' position: fixed;' +
' opacity: 0;' +
'}' +
'.back-to-top.active {' +
@srfrnk
srfrnk / heroku set config var
Created April 15, 2014 08:18
setting a config var that contains JSON object
setting a config var that contains JSON object:
heroku config:set CONNECTION_OPTIONS={\"userName\":\"...\",\"password\":\"...\",\"server\":\"...\",\"options\":{\"database\":\"...\"}}
@srfrnk
srfrnk / ngHold.js
Last active February 15, 2021 09:59
angular directive: repeat action while mouse is clicked down for a long period of time and until the mouse is released.
define("directives/ngHold", ["app"], function (app) {
return app.directive('ngHold', [function () {
return {
restrict: "A",
link: function (scope, elm, attrs) {
},
controller: ["$scope", "$element", "$attrs", "$transclude", "$timeout", function ($scope, $element, $attrs, $transclude, $timeout) {
var onHold = function () {
return $scope.$eval($attrs.ngHold);
@srfrnk
srfrnk / windows cmd
Last active August 29, 2015 14:02
globaly setting npm install builds to use visual studio 2012 instead of the default vs2010
npm config set msvs_version 2012 --global
@srfrnk
srfrnk / captureClick.js
Created June 27, 2014 07:39
NG directive to disable click event from bubbling up...
define("directives/captureClick", ["app"], function (app) {
return app.directive('captureClick', [function () {
return {
restrict: "A",
controller: ["$scope", "$element", "$attrs", "$transclude", function ($scope, $element, $attrs, $transclude) {
$element.click(function (e) {
e.stopPropagation();
});
}]
};
@srfrnk
srfrnk / onlyCrawlers.js
Created July 5, 2014 09:33
A NodeJs ExpressJS middleware to allow bot/crawler specific routes. Based on the OS project Prerender.IO middleware for node.
require("requirejs").define("middleware/onlyCrawlers", ["url"], function (url) {
var crawlerUserAgents = [
// 'googlebot',
// 'yahoo',
// 'bingbot',
'baiduspider',
'facebookexternalhit',
'twitterbot',
'rogerbot',
'linkedinbot',
require("requirejs").define("models/elasticsearchHelper", [], function () {
var Q = require("q");
var ElasticSearchClient = require("elasticsearchclient");
var serverOptions = JSON.parse(process.env.ES_SERVER_OPTIONS || "null") || {
host: "dwalin-us-east-1.searchly.com",
port: 443,
secure: true,
auth: {
username: "site",
require("requirejs").define("models/emailHelper", [], function () {
var Q = require("q");
var emailjs = require("emailjs");
var ejs = require('ejs');
var fs = require('fs');
var path = require('path');
return {
send: function (templatePath,data,to,subject) {
var q= Q.defer();
require("requirejs").define("models/redisHelper", [], function () {
var Q = require("q");
var redis = require("redis");
var connectionOptions = JSON.parse(process.env.REDIS_CONNECTION_OPTIONS);
var client = redis.createClient(connectionOptions.port, connectionOptions.host, {});
client.auth(connectionOptions.password, function (err, reply) {
if(!!err)
{
console.log(err);
}
require("requirejs").define("models/serverUtils", [], function () {
return {
getClientIp: function (req) {
// snippet taken from http://catapulty.tumblr.com/post/8303749793/heroku-and-node-js-how-to-get-the-client-ip-address
var ipAddress;
// The request may be forwarded from local web server.
var forwardedIpsStr = req.header('x-forwarded-for');
if (forwardedIpsStr) {
// 'x-forwarded-for' header may return multiple IP addresses in
// the format: "client IP, proxy 1 IP, proxy 2 IP" so take the