Skip to content

Instantly share code, notes, and snippets.

View rolaveric's full-sized avatar

Jason Stone rolaveric

View GitHub Profile
@rolaveric
rolaveric / gopherjsResult.js
Created March 7, 2014 08:19
The result from building gopherjsIntroMain.go with GopherJS
"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;
@rolaveric
rolaveric / gopherjsModelOriginal.js
Last active August 29, 2015 13:57
Example of an existing legacy Javascript object we want to port to Go.
// User Type
function User(name, id) {
this.name = name;
this.id = id;
this.save = function () {
DB.query('UPDATE User SET name = ? WHERE id = ?', this.name, this.id);
}
}
@rolaveric
rolaveric / gopherjsModel.js
Last active August 29, 2015 13:57
Example of gopherjsModelOriginal.js refactored to better match a Go API.
// Namespace created within an IIFE for private scope
var user = (function () {
// Variable for holding the injected DB interface
var DB;
// User Type
function User(name, id) {/* ... */}
return {
// Expose a function for setting the DB interface
@rolaveric
rolaveric / gopherjsModel.go
Last active August 29, 2015 13:57
Example of a Javascript model object converted to Go
package user
// Interface for a database result row
type DBRow interface {
GetInt(colnum int) int
GetString(colnum int) string
}
// Interface for a database result
type DBResult interface {
@rolaveric
rolaveric / angularDependencyInjection.dart
Created March 29, 2014 11:08
Example of DI working in AngularDart.
// Simple class holding some configuration
class ConfigService{
String text;
ConfigService() {
this.text = "Meep!";
}
}
@NgDirective(selector: '[sample-text-id]')
class ReverseClickDirective{
@rolaveric
rolaveric / angularBoilerplate.dart
Created March 29, 2014 04:50
Most basic boilerplate required for an AngularDart application.
import 'package:angular/angular.dart';
main() {
ngBootstrap();
// ...
}
@rolaveric
rolaveric / angularAnnotation.js
Created March 29, 2014 12:29
Example of how annotations look in Javascript post-traceur compilation.
/*
* @NgFilter(name: 'myfilter')
* function MyFilter() {}
*/
function MyFilter() {}
MyFilter.annotations = [new NgFilter({name: 'myFilter'})];
@rolaveric
rolaveric / angularDirective.dart
Last active August 29, 2015 13:57
Simple example of a directive in AngularDart.
import 'dart:html';
import 'package:angular/angular.dart';
// Annotation which states that this class is a directive which should be
// attached to elements with a 'sample-text-id' attribute
@NgDirective(selector: '[sample-text-id]')
class ReverseClickDirective{
// The element that the directive is attached to
Element element;
@rolaveric
rolaveric / angularDirective.html
Created March 29, 2014 05:33
HTML changed from using an "id" attribute to a custom "sample-text-id" attribute.
<div id="sample_container_id">
<p sample-text-id>Click me!</p>
</div>
@rolaveric
rolaveric / protractorClickTest.js
Last active August 29, 2015 14:00
Simple protractor test which find an element, clicks it, then checks it's text value.
describe('click to reverse', function () {
var btn;
it('Reverses the button label on click', function () {
// load the page
browser.get('http://localhost:63342/protractorDemo/index.html');
// Find the button
btn = element(by.binding('click.btnText'));