Abnormal behavior of using jQuery Deferred to show loading processor

Maybe I should refine my example.

    function doSomethingHeavy() {
        // emulate do something heavy
        var now = new Date().getTime();
        while (new Date().getTime() < now + 5000) {
            // do nothing
        }
    }

    $("#testButton").bind("click.performTest", function () {
        $("#loading").show();
        doSomethingHeavy();
        $("#loading").hide();
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button type="button" id="testButton">Perform Test</button>
<div id="loading" style="display:none" >Loading</div>

read more

Abnormal behavior of using jQuery Deferred to show loading processor

Maybe I should refine my example.

    function doSomethingHeavy() {
        // emulate do something heavy
        var now = new Date().getTime();
        while (new Date().getTime() < now + 5000) {
            // do nothing
        }
    }

    $("#testButton").bind("click.performTest", function () {
        $("#loading").show();
        doSomethingHeavy();
        $("#loading").hide();
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button type="button" id="testButton">Perform Test</button>
<div id="loading" style="display:none" >Loading</div>

read more

AngularJS – Directive link function won’t trigger after element is created from another directive

I’m making a data form and part of it requires that it have a button to add another row of questions and another button to delete it’s corresponding row. Hopefully I’ve just overlooked something and it’s a simple fix, but if I have to reorganize any code I will. The problem I’m having is that when you click Add Stack it adds a new row of questions exactly like it’s supposed to, but when you click Delete Stack nothing happens. From various methods of debugging I’ve found that the problem stems from the fact that the delete button is generated, and if I were to put a row that loads initially with the page it works just like it’s supposed to. I would also like to point out that for the purposes of debugging the delete button just prints “test” to the console instead of actually deleting a row.

The relevant files are as following:

app.js

/*global angular*/

var app;
app = angular.module('app', ['ngRoute']);

app.config(['$routeProvider', function ($routeProvider) {
    'use strict';

    $routeProvider.when('/', {
        templateUrl: 'html/home.html'
    }).otherwise({
        redirectTo: '/'
    });

}]);

app.controller('MainController', function ($scope, $http) {
    'use strict';

    $http.get('json/data.json').then(function (response) {
        $scope.data = response.data;
    });

    $scope.change = function (item) {
        return item + '-changed';
    };
});

app.directive('removeStackButton', function() {
    return {
        link: function(scope, element) {
            scope.removeStack = function() {
                console.log("test");
            }
        }
    }
});

app.directive('addStackButton', ['$http', function($http) {
    return {
        link: function(scope, element) {
            scope.addStack = function() {
                $http.get('html/stack.html').then(function (response) {
                    var row = $compile(response.data)(scope);
                    element.parent().parent().prepend(row);
                });
            }
        }
    }
}]);

read more

File.write doesn’t write

I’m enjoying a very interesting problem where File.write... only works occasionally, i.e., seemingly when it’s at the end of the method. For some weird reason this works:

 def update(id)
   r = HTTParty.get("#{user_api_url}/#{id}?token=#{token}").parsed_response
   file_path = "/Users/#{server_user}/server/resources/users/"
   File.write("#{file_path}#{id}#{extension(r['user_file_name'])}", open("#{r['user_url']}").read, { mode: 'wb' })
   File.write("#{file_path}#{id}_logo#{extension(r['logo_file_name'])}", open("#{r['user_logo_url']}").read, { mode: 'wb' })
 end

And this doesn’t:

 def update(id)
   r = HTTParty.get("#{user_api_url}/#{id}?token=#{token}").parsed_response
   file_path = "/Users/#{server_user}/server/resources/users/"
   r['shared_resources'].map do |key, value|
     file = "#{file_path}shared_resources/#{value.split('/')[-1]}"
     p "#{timestamp}: Saving #{key} from #{api_server}#{value} into #{file}"
     File.write(file, open("#{api_server}#{value}").read, mode: 'wb')
   end
   File.write("#{file_path}#{id}#{extension(r['user_file_name'])}", open("#{r['user_url']}").read, mode: 'wb')
   File.write("#{file_path}#{id}_logo#{extension(r['logo_file_name'])}", open("#{r['user_logo_url']}").read, mode: 'wb')
 end

read more

File.write doesn’t write

I’m enjoying a very interesting problem where File.write... only works occasionally, i.e., seemingly when it’s at the end of the method. For some weird reason this works:

 def update(id)
   r = HTTParty.get("#{user_api_url}/#{id}?token=#{token}").parsed_response
   file_path = "/Users/#{server_user}/server/resources/users/"
   File.write("#{file_path}#{id}#{extension(r['user_file_name'])}", open("#{r['user_url']}").read, { mode: 'wb' })
   File.write("#{file_path}#{id}_logo#{extension(r['logo_file_name'])}", open("#{r['user_logo_url']}").read, { mode: 'wb' })
 end

And this doesn’t:

 def update(id)
   r = HTTParty.get("#{user_api_url}/#{id}?token=#{token}").parsed_response
   file_path = "/Users/#{server_user}/server/resources/users/"
   r['shared_resources'].map do |key, value|
     file = "#{file_path}shared_resources/#{value.split('/')[-1]}"
     p "#{timestamp}: Saving #{key} from #{api_server}#{value} into #{file}"
     File.write(file, open("#{api_server}#{value}").read, mode: 'wb')
   end
   File.write("#{file_path}#{id}#{extension(r['user_file_name'])}", open("#{r['user_url']}").read, mode: 'wb')
   File.write("#{file_path}#{id}_logo#{extension(r['logo_file_name'])}", open("#{r['user_logo_url']}").read, mode: 'wb')
 end

read more