Skip to content

Instantly share code, notes, and snippets.

View didil's full-sized avatar

Adil H didil

View GitHub Profile
@didil
didil / foodcircles_tech.md
Last active January 3, 2016 05:39
Testing / Environments / Deployment advice for FoodCircles

Environments

The project is missing properly maintained, cleanly separated environments, especially :

Development environment

  • A proper development database and seed data
  • Development API Keys, these can be hidden from the codebase using the figaro gem

Staging environment

  • A staging server running on a different box with an independent DB
  • Staging API Keys using the figaro gem again
# network names are set in the truffle config
$ truffle console --network=a
# company A votes, while making the transaction private and only visible by the regulator, "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=" is the Regulator Node's key in our setup
truffle(a)> SecretBallot.deployed().then((instance) => instance.vote(1, {privateFor: ["BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="]}))
# Check vote count for option 1
truffle(a)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(1)).then((result) => result.toNumber())
1
# Check vote count for option 2
truffle(a)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(2)).then((result) => result.toNumber())
0
$ truffle console --network=b
# company B votes, while making the transaction private and only visible by the regulator, "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=" is the Regulator Node's key in our setup
truffle(b)> SecretBallot.deployed().then((instance) => instance.vote(1, {privateFor: ["BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="]}))
# Check vote count for option 1
truffle(b)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(1)).then((result) => result.toNumber())
1
# Check vote count for option 2
truffle(b)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(2)).then((result) => result.toNumber())
0
$ truffle console --network=c
# company C votes, while making the transaction private and only visible by the regulator, "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=" is the Regulator Node's key in our setup
truffle(c)> SecretBallot.deployed().then((instance) => instance.vote(2, {privateFor: ["BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo="]}))
# Check vote count for option 1
truffle(c)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(1)).then((result) => result.toNumber())
0
# Check vote count for option 2
truffle(c)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(2)).then((result) => result.toNumber())
1
$ truffle console
truffle(regulator)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(1)).then((result) => result.toNumber())
2
truffle(regulator)> SecretBallot.deployed().then((instance) => instance.getTotalVotes(2)).then((result) => result.toNumber())
1
@didil
didil / results.csv
Last active December 28, 2017 17:28
Option 1 votes Option 2 votes
Regulator's view 2 1
Company A's view 1 0
Company B's view 1 0
Company C's view 0 1
pragma solidity ^0.4.15;
contract SecretBallot {
/*
* Storage
*/
// votes per company
mapping(address => uint) private votes;
@didil
didil / serverless.yml
Created July 16, 2018 11:09
Defining the API Gateway endpoint
functions:
asyncConcat:
handler: functions/asyncConcat.handler
events:
- http:
path: asyncConcat
method: get
cors: true
@didil
didil / asyncConcat.js
Created July 16, 2018 11:14
asyncConcat lambda handler
const jsonResponse = require("../lib/jsonResponse");
const asyncConcatService = require("../lib/asyncConcatService");
module.exports.handler = async (event, context) => {
let { a, b } = event.queryStringParameters;
if (!a || !b) {
return jsonResponse.error({
message: "Please specify 2 strings a and b to concatenate"
});
function concat(a, b) {
return new Promise((resolve, reject) => {
setImmediate(() => resolve(`${a} ${b}`));
});
}
module.exports = {
concat
};