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
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
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
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
cols, err := rows.Cols() | |
// rows.Scan wants '[]interface{}' as an argument, but we want the values | |
// loaded into a '[]string'. So we must copy the references into such a slice | |
// See http://code.google.com/p/go-wiki/wiki/InterfaceSlice for details | |
scanArgs := make([]interface{}, len(cols)) | |
values := make([]string, len(cols)) | |
for i := range values { | |
scanArgs[i] = &values[i] | |
} |
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
// X needs anything | |
func X(anything interface{}) { | |
// Nothing comes for free - need to see what I got | |
switch value := anything.(type) { | |
case string: | |
fmt.Printf("I got a string!: %s", value) | |
default: | |
fmt.Print("I got... something!") | |
} | |
} |
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() | |
} |
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
"use strict"; | |
(function() { | |
Error.stackTraceLimit = -1; | |
var go$reservedKeywords = ["abstract", "arguments", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default", "delete", "do", "double", "else", "enum", "eval", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto", "if", "implements", "import", "in", "instanceof", "int", "interface", "let", "long", "native", "new", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "typeof", "var", "void", "volatile", "while", "with", "yield"]; | |
var go$global; | |
if (typeof window !== "undefined") { | |
go$global = window; |
OlderNewer