Skip to content

Instantly share code, notes, and snippets.

@jrmoran
jrmoran / app.js
Created December 20, 2012 07:17
AngularJS Event delegation in a repeater. SO 13965627
var app = angular.module('app', []);
app.controller('ctrl', function($scope){
$scope.ss = [
{name:'test1'},
{name:'test2'},
{name:'test3'},
{name:'test4'},
{name:'test5'}
];
@jrmoran
jrmoran / app.js
Created December 17, 2012 00:30
AngularJS. Run a function from a directive's controller when ngRepeat is done evaluating an expression
var app = angular.module('app', []);
app.controller('ctrl', function($scope){
$scope.images = [ {name: 'test1'}, {name: 'test2'},
{name: 'test3'}, {name: 'test4'}];
});
app.directive('gallery',function() {
return {
restrict : 'C',
@jrmoran
jrmoran / app.js
Created December 15, 2012 04:07
AngularJS filtering object and modules. view here http://jsbin.com/acagag/4/edit. (SO 13887504)
angular.module('utils', [])
.factory('utils', function(){
return{
compareStr: function(stra, strb){
stra = ("" + stra).toLowerCase();
strb = ("" + strb).toLowerCase();
return stra.indexOf(strb) !== -1;
}
};
});
@jrmoran
jrmoran / interceptor.js
Created December 11, 2012 07:06
AngularJS intercept responses - array of strings to array of objects
app.config( function( $httpProvider ) {
var interceptor = function( $q ) {
return function( promise ) {
var success = function(res) {
if(res.data && res.data[0]){
if(typeof res.data[0] === 'string'){
var data = res.data,
ret = [];
@jrmoran
jrmoran / grunt.js
Created December 6, 2012 17:35
Basic Grunt concat and minification set up
module.exports = function(grunt) {
grunt.initConfig({
concat: {
js: {
src: 'src/js/*.js',
dest: 'dest/js/concat.js'
},
css: {
src: 'src/css/*.css',
@jrmoran
jrmoran / rakefile.rb
Created December 4, 2012 03:18
Sprockets 2.8.1 Precompile CoffeeScript for non rack apps
namespace :js do
require 'sprockets'
environment = Sprockets::Environment.new(File.dirname(__FILE__))
environment.append_path 'src/bower'
environment.append_path 'src/coffee'
source_code = environment['app.coffee']
desc 'compile CoffeeScript with Sprockets'
task :compile do
@jrmoran
jrmoran / many-directives.haml
Created November 30, 2012 01:43
AngularJS - precompiled Haml
%ng-form(name="circleEditForm")
%label Circle Name:
%input(type="text" name="circleName" |
ng-minlength= 3 |
ng-model="circleModal.name" |
ng-maxlength= 8 |
maxlength= 8 |
required |
ng-class="{error: !circleEditForm.circleName.$valid}" )
@jrmoran
jrmoran / controllers.coffee
Created November 28, 2012 18:43
AngularJS Testing Controllers with Testacular & Testem
# = require '../components/jquery/jquery'
# = require '../components/angular-complete/angular'
Controllers = angular.module 'controllers', []
Controllers.controller 'PhoneListCtrl', ['$scope', ($scope)->
$scope.phones = [
{name: "Nexus S", snippet: "Fast just got faster with Nexus S."},
@jrmoran
jrmoran / test.js
Created November 16, 2012 07:00
test
var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
console.log(evens);
var appendStyle = function(){
var htmlstr = '<link rel="stylesheet" '+
'href="https://gist.github.com/stylesheets/gist/embed.css" '+
'type="text/css" />';
$('head').append( htmlstr );
}
/*
look for tags [gist]#######[/gist] and for each one found, insert a
div with an id attribute that references the gist's id