Skip to content

Instantly share code, notes, and snippets.

View rotemtam's full-sized avatar

Rotem Tamir rotemtam

View GitHub Profile
@rotemtam
rotemtam / kahoot-clone-schematic-host.html
Created September 9, 2015 21:37
Schematic Host view
<div class="row" ng-if="game.data.state == 'waitingForPlayers'">
...
</div>
<div class="row" ng-if="game.data.state == 'preQuestion'">
...
</div>
<div class="row" ng-if="game.data.state == 'question'">
...
@rotemtam
rotemtam / kahoot-partial-host-controller.js
Last active September 9, 2015 21:52
Using $scope.$watch to respond to game state changes
$scope.$watch('game.data.state', function(newValue, oldValue) {
switch(newValue) {
case 'preQuestion':
$scope.countdown = 5;
$interval(function() {
$scope.countdown--;
},1000, $scope.countdown)
.then(function() {
@rotemtam
rotemtam / kahoot-clone-host-service.js
Created September 12, 2015 16:25
Kahoot Clone Host.js service
angular.module('kahootCloneApp')
.service('Host', function (fbutil, Trivia) {
var self = this, _so;
self.init = function(PIN) {
self.syncObject = fbutil.syncObject('games/' + PIN);
_so = self.syncObject;
return self.syncObject.$loaded();
};
@rotemtam
rotemtam / kahoot-cline-player-service.js
Created September 12, 2015 16:27
Kahoot Clone player service
angular.module('kahootCloneApp')
.service('Player', function (fbutil, _, $cookieStore) {
// AngularJS will instantiate a singleton by calling "new" on this function
var self = this, _so;
self.getUniqId = function() {
// generate a unique idenftifier for the player and save it in a cookie to allow refreshes
if($cookieStore.get('playerId')) {
return self._id = $cookieStore.get('playerId');
} else {
@rotemtam
rotemtam / add_cname_route53.py
Created August 3, 2016 16:36
Add a CNAME record in Route53 using python boto3
import boto3
client = boto3.client('route53')
def add_cname_record(source, target):
try:
response = client.change_resource_record_sets(
HostedZoneId='<hosted zone id>',
ChangeBatch= {
'Comment': 'add %s -> %s' % (source, target),
@rotemtam
rotemtam / some-lambda-func.spec.js
Last active August 18, 2016 09:39
Node.js AWS Lambda Unit Test with a Mock Context object
'use strict';
const expect = require('chai').expect
, SomeLambda = require('./some-lambda-func')
, MockContext = require('./mock-lambda-context');
describe('Some Lambda Func', function() {
let ctx;
before(function() {
@rotemtam
rotemtam / some-lambda-func.js
Created August 18, 2016 09:36
some-lambda-function
'use strict';
module.exports = function doSomething(e, ctx, cb) {
if (e.someParam > 0) {
ctx.succeed('Yay');
// we add the callback here to make it testable
// we'll show in the next step how we make this DRY
if (cb) cb();
} else {
ctx.fail('Nay')
@rotemtam
rotemtam / example-lambda-runner.js
Created August 18, 2016 09:59
Example Lambda with Lambda Runner
'use strict';
const LambdaRunner = require('co-lambda-runner')
, DB = require('./db');
function *main(e) {
let id = e.params.id;
return yield DB.get(id);
}
@rotemtam
rotemtam / co-mocha-runner.js
Created August 18, 2016 10:07
LambdaRunner - interface between ES6 generators and lambda functions
'use strict';
const co = require('co');
module.exports = function(lambda) {
return function(e, ctx, cb) {
co(
function* () {
let result = yield lambda(e, ctx);
├── Dockerfile
├── infra
│   └── webpack.config.js
├── package.json
└── src
├── functions
│   └── getRepositories
│   ├── function.json
│   ├── src
│   │   └── index.js