Skip to content

Instantly share code, notes, and snippets.

@scottmas
scottmas / ngTap.js
Created December 18, 2013 20:01 — forked from mhuneke/ngTap.js
app.directive("ngTap", ["$parse", function($parse) {
return function($scope, $element, $attributes) {
var tapped;
tapped = false;
$element.bind("click", function(event) {
if (!tapped) {
var fn = $parse($attributes["ngTap"]);
$scope.$apply(function() {
fn($scope, {$event:event});
});
@g-alonso
g-alonso / interceptor.js
Last active January 1, 2016 12:29
Angular Http Interceptor
var interceptor = angular.module('Interceptor',[]);
interceptor.factory('HttpInterceptor', function ($q, $rootScope, $log) {
var numLoadings = 0;
return {
request: function (config) {
numLoadings++;
@demisx
demisx / angularjs-providers-explained.md
Last active December 26, 2024 05:39
AngularJS Providers: Constant/Value/Service/Factory/Decorator/Provider
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

@amoilanen
amoilanen / running.command.node.js
Created May 9, 2014 20:39
Running command from Node.js by spawning a new process
var spawn = require('child_process').spawn;
function spawnProcess(dir, cmd) {
return (process.platform.toLowerCase().indexOf("win") >= 0)
? spawnWindowsProcess(dir, cmd)
: spawnLinuxProcess(dir, cmd);
}
function spawnWindowsProcess(dir, cmd) {
return spawn("cmd.exe", ["/c", cmd], {cwd: dir});
@staltz
staltz / introrx.md
Last active April 24, 2025 06:10
The introduction to Reactive Programming you've been missing
@jehoshua02
jehoshua02 / scrollCap.js
Last active August 29, 2015 14:05
Prevent over-scroll, scroll freeze, scroll "bounce", or whatever you call it, on Safari Mobile.
var scrollCap = function ($element) {
$element.on('touchstart.scroll-cap', function(event){
var $element = $(this);
var scrollTop = $element.scrollTop();
var contentHeight = $element.get(0).scrollHeight;
var minScrollTop = 1;
var maxScrollTop = contentHeight - $element.height() - 1;
if(scrollTop < minScrollTop){
$element.scrollTop(minScrollTop);
@bvaughn
bvaughn / overview-for-angular-apps-with-roles-and-permissions.md
Last active April 28, 2017 11:51
RE: Reddit Angular JS question "Advice on separating the logical parts of an application"

This gist is in response to a question asked on the Reddit Angular JS forum about how to structure an Angular app with roles and permissions.

There are many ways to approach this, but I'll share one that I've used before and maybe it will give you an idea. I'd combine all of the above into a single app and control who gets to see what using permissions. There are a few components to this approach...

A local session service

First off I'd advise creating some sort of local session management service. This should be able to track whether you have an authenticated user and- if so- what types of permissions that user has. (Lots of ways to manage permissions. I'll assume your user object has either a 'role' enum or something simple like an array of string permissions.) You could roll your own session service or you could check out something like satellizer.

Let's assume yo

@mlynch
mlynch / auth.markdown
Last active September 4, 2020 18:11
AngularJS Authentication and CORS

Single Page Apps are ruling the world and AngularJS is leading the charge. But many of the lessons we learned in the Web 2.0 era no longer apply, and few are as drastically different as authentication.

CORS

CORS is an oft-misunderstood feature of new browsers that is configured by a remote server. CORS stands for Cross-Origin-Resource-Sharing, and was designed to make it possible to access services outside of the current origin (or domain) of the current page.

Like many browser features, CORS works because we all agree that it works. So all major browsers like Chrome, Firefox, and IE support and enforce it. By using these browsers, you benefit from the security of CORS.

That means certain browsers do not enforce it, so it is not relevant there. One large example is a native Web View for things like Cordova and Phonegap. However, these tools often have configuration options for whitelisting domains so you can add some security that way.

(function () {
'use strict';
// Define the factory on the module.
// Inject the dependencies.
// Point to the factory definition function.
angular.module('brew-everywhere').factory('messaging_service',
[messaging_service]);
function messaging_service() {
@carbonrobot
carbonrobot / rightClick.directive.js
Created October 15, 2014 19:29
Angular Right Click Directive
(function () {
/*
* @name ngRightClick
* @type Directive
* @desc Binds the right click to a javascript function by using the ng-right-click attribute
*/
function ngRightClick($parse) {
return function (scope, element, attrs) {