This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="text" id="messageInput"/> | |
<span id="messageOutput"></span> | |
<script type="text/javascript"> | |
(function () { | |
var input = document.getElementById('messageInput'); | |
var output = document.getElementById('messageOutput'); | |
input.addEventListener('change', function () { | |
output.innerHTML = input.value; | |
}); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div ng-app=""> | |
<input type="text" ng-model="message"/> | |
{{message}} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.directive('ngHide', [function () { | |
return function (scope, element, attr) { | |
scope.$watch(attr.ngShow, function ngHideWatchAction(value){ | |
// Call "addClass()" or "removeClass()" based on the attribute value | |
// AngularJS already declares the CSS for the "ng-hide" class | |
element[value ? 'removeClass' : 'addClass']('ng-hide'); | |
}); | |
}; | |
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('ngHide', function() { | |
it('should hide an element', inject(function($rootScope, $compile) { | |
var element = angular.element('<div ng-hide="exp"></div>'); | |
element = $compile(element)($rootScope); | |
expect(element).toBeShown(); | |
$rootScope.exp = true; | |
$rootScope.$digest(); | |
expect(element).toBeHidden(); | |
})); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('myServiceProvider', function () { | |
var p; | |
// Uses the "module()" method to get a reference to the provider during the "config" phase | |
beforeEach(module('myModule', function (myServiceProvider) { | |
p = myServiceProvider; | |
})); | |
// Runs "inject()" so that the module gets instantiated. | |
// Because "myService" isn't injected, the "myServiceProvider" should still be pristine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"fmt" | |
) | |
func main() { | |
// New functionality written in Go | |
http.HandleFunc("/new", func(w http.ResponseWriter, r *http.Request) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/go-martini/martini" | |
) | |
func main() { | |
// Create a new Martini server | |
m := martini.New() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func Triple(input int) int { | |
// This line would be really awkward if we were allowed to accept a string | |
return input * 3 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func DoSomething(callback func(message string) error) { | |
// Good thing I know this function will take a message string and return a single error response | |
err := callback("Did something good!") | |
if err != nil { | |
panic(err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A Doer is anything that will Do something | |
type Doer interface { | |
Do() | |
} | |
// X needs a Doer | |
func X(doer Doer) { | |
doer.Do() | |
} |