Skip to content

Instantly share code, notes, and snippets.

@spenserhuang
spenserhuang / main.js
Last active December 28, 2017 06:36
Starting Code
let jsChain = new Blockchain();
jsChain.addBlock(new Block("12/25/2017", {amount: 5}));
jsChain.addBlock(new Block("12/26/2017", {amount: 10}));
console.log(JSON.stringify(jsChain, null, 4));
console.log("Is blockchain valid? " + jsChain.checkValid());
@spenserhuang
spenserhuang / main.js
Last active December 28, 2017 06:36
Block + Blockchain w/ Mining
const SHA256 = require('crypto-js/sha256')
class Block {
constructor(timestamp, data) {
this.index = 0;
this.timestamp = timestamp;
this.data = data;
this.previousHash = "0";
this.hash = this.calculateHash();
this.nonce = 0;
@spenserhuang
spenserhuang / main.js
Last active December 28, 2017 06:35
Blockchain Object
class Blockchain{
constructor() {
this.chain = [this.createGenesis()];
}
createGenesis() {
return new Block(0, "01/01/2017", "Genesis block", "0")
}
@spenserhuang
spenserhuang / main.js
Last active December 28, 2017 06:35
Block Object with calculateHash Function
const SHA256 = require('crypto-js/sha256')
class Block {
constructor(timestamp, data) {
this.index = 0;
this.timestamp = timestamp;
this.data = data;
this.previousHash = "0";
this.hash = this.calculateHash();
this.nonce = 0;
@spenserhuang
spenserhuang / main.js
Last active December 28, 2017 06:35
js-blockchain Step 1
class Block {
constructor(timestamp, data) {
this.index = 0;
this.timestamp = timestamp;
this.data = data;
this.previousHash = "0";
this.hash = this.calculateHash();
this.nonce = 0;
}
@spenserhuang
spenserhuang / elixir-resources.md
Last active April 8, 2018 17:36
List of Elixir Resources
//------------------------------------------------------------------------------------------------------------------
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here.
//------------------------------------------------------------------------------------------------------------------
function Animal ( name, num_of_legs ) {
this.name = name;
this.num_of_legs = num_of_legs;
}
Animal.prototype.identify = function() {
@spenserhuang
spenserhuang / Database_Drill:_Intro_to_SQLite_solution.rb
Last active August 29, 2015 14:20
Solution for Database Drill: Intro to SQLite
# Solution for Challenge: Database Drill: Intro to SQLite. Started 2015-05-09T04:09:18+00:00
sqlite>
sqlite> .schema
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name VARCHAR(64) NOT NULL,
last_name VARCHAR(64) NOT NULL,
email VARCHAR(128) UNIQUE NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
@spenserhuang
spenserhuang / gist:d625e87df6053a28cd34
Last active August 29, 2015 14:20
CSV and MVC Notes 05/07/2015
# There may be a few typos here and there and I also did not put up the Twilio Portion.
# ------------------------------------------------------------
# CSV
# ------------------------------------------------------------
require 'csv'
class Person