Skip to content

Instantly share code, notes, and snippets.

View rolaveric's full-sized avatar

Jason Stone rolaveric

View GitHub Profile
@rolaveric
rolaveric / reverseProxy.go
Created February 23, 2014 06:25
Example of a reverse proxy written in Go
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) {
@rolaveric
rolaveric / mixinSchema.json
Created March 28, 2015 02:29
Example of using "allOf" to make JSON Schema mixins
{
"definitions": {
"nameMixin": {
"type": "object",
"properties": {
"nameFirst": {"type": "string"},
"nameLast": {"type": "string"}
},
"required": ["nameFirst", "nameLast"]
},
@rolaveric
rolaveric / relationship.js
Created March 28, 2015 02:04
Example of a relationship definition for JSON Schema design
/*
For this schema, each object's relationships are defined as an object under
a "links" property.
Each property of that object is the name of the relationship, and the value
is a single object with the "type" and "id" of the related object.
For "to-many" relationships, the value can be an array of the same objects.
*/
var data = {
"articles": [{
"id": "article1",
@rolaveric
rolaveric / gopherjsIntroMain.go
Last active September 28, 2017 15:39
A simple example of a Go library, and how to expose it to the global scope when run through GopherJS.
package main
import (
"github.com/gopherjs/gopherjs/js"
"github.com/rolaveric/pet"
)
func main() {
js.Global.Set("pet", map[string]interface{}{
"New": pet.New,
@rolaveric
rolaveric / angular2Class.js
Created October 31, 2014 07:55
ES6 Class and equivalent ES5 code
// ES6 Class
class MyClass {
constructor() {
this.a = "b";
}
getA() {
return this.a;
}
}
@rolaveric
rolaveric / bindingWithAngular.html
Created January 26, 2014 22:25
Reasons to use AngularJS: With Angular
<div ng-app="">
<input type="text" ng-model="message"/>
{{message}}
</div>
@rolaveric
rolaveric / controllerFakeScope.js
Created January 26, 2014 22:17
AngularJS Unit Test: Controller, fake scope
it('Attaches the scope to itself', inject(function ($controller) {
var fakeScope = {};
var ctrl = $controller('MyCtrl', "$scope": fakeScope});
expect(ctrl.scope).toBe(fakeScope);
}));
@rolaveric
rolaveric / bindingWithoutAngular.html
Created January 26, 2014 22:23
Reasons to use AngularJS: Without Angular
<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;
});
})();
@rolaveric
rolaveric / filterSimple.js
Created January 26, 2014 22:14
AngularJS Unit Test: Filter, simple
it('Capitalises strings', inject(function (capitaliseFilter) {
expect(capitaliseFilter('abcd')).toEqual('Abcd');
}));
@rolaveric
rolaveric / filterComplex.js
Created January 26, 2014 22:16
AngularJS Unit Test: Filter, complex
it('Capitalises strings', inject(function ($filter) {
expect($filter('capitalise')('abcd')).toEqual('Abcd');
}));