Skip to content

Instantly share code, notes, and snippets.

@ajb413
ajb413 / flatten.js
Created December 20, 2015 21:43
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
//Set the array of arbitrarily nested arrays to startArray
//The flattened array is stored in endArray after flatten(startArray) is executed
var startArray = [[1,2,[3]],4];
var endArray = new Array();
flatten(startArray);
console.log('original: ' + startArray);
console.log('flattened: ' + endArray);
@ajb413
ajb413 / ReadReceiptDemo.html
Last active October 6, 2016 00:29
PubNub Read Receipt Example
<html>
<body>
<div class="readReceiptDemo">
<input id="readMessages" type="submit" value="I've read all the messages" />
<br />
<input id="msgText" type="text" />
<input id="sendMsg" type="submit" />
<div id="messagePanel"></div>
</div>
</body>
@ajb413
ajb413 / Token.sol
Created February 14, 2018 18:54
An ERC-20 Ethereum Token.
pragma solidity ^0.4.18;
import 'zeppelin-solidity/contracts/math/SafeMath.sol';
/**
* Token
*
* @title A fixed supply ERC20 token contract.
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md
*/
const EthereumTx = require('ethereumjs-tx');
const privateKeys = require('./truffle-keys').private;
const publicKeys = require('./truffle-keys').public;
const Token = artifacts.require('./Token.sol');
contract('Token (integration)', function(accounts) {
let contract;
let owner;
let web3Contract;
const Token = artifacts.require('Token');
module.exports = (deployer) => {
deployer.deploy(Token);
};
const mnemonic = process.env.ethereum_mnemonic;
const HDWalletProvider = require("truffle-hdwallet-provider");
require('babel-register');
require('babel-polyfill');
module.exports = {
build: "npm run dev",
networks: {
development: {
@ajb413
ajb413 / app.js
Created February 14, 2018 19:06
Pubnub config in test app for crowdsale
var pubnub = new PubNub({
publishKey : '__YOUR_PUBNUB_PUBLISH_KEY__',
subscribeKey : '__YOUR_PUBNUB_SUBSCRIBE_KEY__'
});
var pubnubSMSChannel = '__YOUR_FUNCTION_LISTENING_CHANNEL__';
@ajb413
ajb413 / sms-handler.js
Created February 14, 2018 19:07
Pubnub Functions config in test app for crowdsale
const xhr = require('xhr');
const basicAuth = require('codec/auth');
const username = '__YOUR_CLICKSEND_USER_NAME__';
const authKey = '__YOUR_CLICKSEND_AUTH_KEY__';
const uri = 'https://rest.clicksend.com/v3/sms/send';
const authorization = basicAuth.basic(username, authKey);
@ajb413
ajb413 / MonitorEthEvents.js
Created February 15, 2018 19:34
Blockchain Event Broadcasting Example
// A node.js app
// Monitors contract events with web3.js and publishes their details over PubNub
const Web3 = require('web3');
const PubNub = require('pubnub');
const abi = require('../build/contracts/ShipmentTracking').abi;
const providerURI = 'https://mainnet.infura.io/__TOKEN_HERE__';
const ethAddress = process.env.contract_address;
@ajb413
ajb413 / integration.test.js
Created February 21, 2018 17:04
Token Presentation tests
const EthereumTx = require('ethereumjs-tx');
const privateKeys = require('./truffle-keys').private;
const publicKeys = require('./truffle-keys').public;
const Token = artifacts.require('./Token.sol');
contract('Token (integration)', function(accounts) {
let contract;
let owner;
let web3Contract;