Skip to content

Instantly share code, notes, and snippets.

View abruzzi's full-sized avatar
⌨️
Writing a React book - React Anti-Patterns

Juntao Qiu abruzzi

⌨️
Writing a React book - React Anti-Patterns
View GitHub Profile
@abruzzi
abruzzi / simple-log-interceptor.js
Last active January 1, 2016 07:19
How to define a interceptor in AngularJS
app.factory('MyHTTPInterceptor', function($q) {
return {
// On response success
response: function (response) {
console.log(response);
// Return the response or promise.
return response || $q.when(response);
},
@abruzzi
abruzzi / directive-controller-communication.html
Last active January 1, 2016 09:09
directive invoke controller methods
<div ng-app="twitterApp">
<div ng-controller="AppCtrl">
<div enter="deleteTweets()">Roll over to load more tweets</div>
</div>
</div>
@abruzzi
abruzzi / angularjs-resource.txt
Last active October 14, 2019 10:50
angularjs resources
http://henriquat.re/directives/advanced-directives-combining-angular-with-existing-components-and-jquery/angularAndJquery.html
http://www.yearofmoo.com/2013/05/enhanced-animations-in-angularjs.html#daneden-animate-css-integration
http://blog.thousandeyes.com/creating-extensible-widgets-part-1-jquery-to-angularjs/
http://codingsmackdown.tv/blog/2012/12/28/mocking-promises-in-unit-tests/
http://blog.brunoscopelliti.com/angularjs-promise-or-dealing-with-asynchronous-requests-in-angularjs
http://markdalgleish.com/2013/06/using-promises-in-angularjs-views/
http://www.codeproject.com/Articles/637430/Angular-js-example-application
https://github.com/dylanfprice/angular-gm
http://nadeemkhedr.wordpress.com/2013/10/18/angularjs-good-unit-test-structure-for-controllers/
http://weblogs.asp.net/dwahlin/archive/2013/05/22/dynamically-loading-controllers-and-views-with-angularjs-and-requirejs.aspx
@abruzzi
abruzzi / chart.html
Created December 26, 2013 12:18
Define a directive
<highchart value="chartData" type="line" width="800" height="400">
</highchart>
define(['angular',
'directives/directives',
'directives/expander-directive'], function() {
describe("expander directives", function() {
var element, scope;
beforeEach(function() {
module('directives');
module('views/expander.html');
inject(function($compile, $rootScope) {
@abruzzi
abruzzi / batch-request.cmd
Created December 27, 2013 08:25
batch for loop
FOR /L %%A in (1, 1, 10) DO (
curl -H "Content-Type:application/json" -H "Accept: application/json" -X POST \
-d @request.json http://host:port/action.do -v -L \
--cookie "key=value" -i
)
@abruzzi
abruzzi / $q.when.txt
Created December 30, 2013 02:31
What does $q.when do?
Calling $q.when takes a promise or any other type, if it is not a promise then it will wrap it in a promise and call resolve. If you pass a value to it then it is never going to be rejected.
From the docs:
Wraps an object that might be a value or a (3rd party) then-able promise into a $q promise. This is useful when you are dealing with an object that might or might not be a promise, or if the promise comes from a source that can't be trusted.
@abruzzi
abruzzi / contact-controller.js
Created December 31, 2013 14:25
nested views in angularjs
var app = angular.module('MyApp');
app.controller('ContactController', ['$scope', function($scope) {
$scope.contacts = ["juntao", "abruzzi"];
$scope.submit = function() {
$scope.$parent.toggleContactsPanel();
};
}]);
@abruzzi
abruzzi / search-setting-controller.js
Created January 2, 2014 08:39
How to mock and test service in angular
define(['controllers/controllers',
'services/search-setting-service'], function(controllers) {
controllers.controller('SearchSettingController',
['$scope', 'SearchSettingService', function($scope, SearchSettingService) {
SearchSettingService.setting().then(function(setting) {
$scope.setting = setting;
$scope.currentVendor = setting.vendors[0];
});
}]);
});
@abruzzi
abruzzi / index-spec.js
Last active November 19, 2016 08:45
E2E test in AngularJS by using protractor
describe("index page", function() {
beforeEach(function() {
browser.get("http://localhost:9999/app/index.html");
});
it("should have navigator", function() {
expect(element("#navigator")).toBeDefined();
});
it("should have input box", function() {