Skip to content

Instantly share code, notes, and snippets.

@rjriel
rjriel / client.js
Last active October 17, 2016 15:14
Source for trying to illustrate socket.io issue
const io = require('socket.io-client')
let socket = io.connect('http://localhost:3000')
socket.on('connect', (data) => {
let playerId
console.log('connected')
socket.on('success', () => {
@rjriel
rjriel / index.js
Created October 27, 2016 14:15
getting started
console.log("Welcome to the Qritter Wars Client")
@rjriel
rjriel / config.js
Last active October 27, 2016 14:45
socket io connect with arguments
module.exports = {
host: "qlikathon.qlik.com",
socketPort: 3000,
apiPort: 8080,
apiId: "<id>",
apiSecret: "<secret>"
}
@rjriel
rjriel / index.js
Last active October 27, 2016 15:07
CREATE OPTIONS FUNCTION
// This is the api key passed to the Qritter Wars REST API in the Authorization header
// for authentication
// format: base64 encoded value of <apiId>:<apiSecret>
const apiKey = new Buffer(`${config.apiId}:${config.apiSecret}`).toString('base64')
let createOptions = (endpoint, method, body) => {
// we need to return all options that the request module expects
// for an http request. 'uri' is the location of the request, 'method'
// is what http method we want to use (most likely GET or POST). headers
// are the http headers we want attached to our request
let getGame = (gameId) => {
return new Promise((resolve, reject) => {
// we want to perform a GET request to the games/:id API
// to retrieve information about the given game
let options = createOptions(`games/${gameId}`, "GET")
request.get(options, (error, res, body) => {
if (error || res.statusCode !== 200) {
console.error("Error Getting Game", error || res.body)
@rjriel
rjriel / index.js
Created October 27, 2016 15:15
FULL START GAME
const io = require("socket.io-client")
const request = require("request")
const config = require("./config")
console.log("Welcome to the Qritter Wars Client")
// This is the api key passed to the Qritter Wars REST API in the Authorization header
// for authentication
// format: base64 encoded value of <apiId>:<apiSecret>
const apiKey = new Buffer(`${config.apiId}:${config.apiSecret}`).toString('base64')
@rjriel
rjriel / index.js
Created October 27, 2016 15:25
PERFORM MOVE (ATTACK ONLY)
let performMove = () => {
// this is where we would put our logic for deciding which move to make
// here we are just attacking all the time. We should probably be more
// creative than this. If we don't heal our Qritter will most likely be
// defeated in no time.
let body = {action: "attack"}
let options = createOptions("moves", "POST", body)
@rjriel
rjriel / index.js
Created October 27, 2016 15:29
MOVE PLAYED
socket.on('move played', (move) => {
// someone has played a move in our game
// if the move just played wasn't by us, it is now
// our turn to play.
if (move.player != playerId) {
console.log(`opponent performed ${move.result}`)
performMove()
}
})
const cheerio = require('cheerio')
const request = require('request')
const mongoose = require('mongoose')
const config = require('config')
const Publication = require('./server/models/publication')
mongoose.Promise = global.Promise
let archives = [
["2016", "12"],
@rjriel
rjriel / Repo.ts
Last active April 8, 2017 18:30
Get Github Info
export class Repo {
name: string;
forks_count: number;
open_issues: number;
constructor(json: {}) {
this.name = json.name;
this.forks_count = json.forks_count;
this.open_issues = json.open_issues;
}