Skip to content

Instantly share code, notes, and snippets.

@spenserhuang
spenserhuang / main.js
Last active Dec 28, 2017
Starting Code
View main.js
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 Dec 28, 2017
Block + Blockchain w/ Mining
View main.js
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 Dec 28, 2017
Blockchain Object
View main.js
class Blockchain{
constructor() {
this.chain = [this.createGenesis()];
}
createGenesis() {
return new Block(0, "01/01/2017", "Genesis block", "0")
}
@spenserhuang
spenserhuang / main.js
Last active Dec 28, 2017
Block Object with calculateHash Function
View main.js
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 Dec 28, 2017
js-blockchain Step 1
View main.js
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 Apr 8, 2018
List of Elixir Resources
View elixir-resources.md
View high-performance-learning-references.md
View zoo.js
//------------------------------------------------------------------------------------------------------------------
// 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 Aug 29, 2015
Solution for Database Drill: Intro to SQLite
View Database_Drill:_Intro_to_SQLite_solution.rb
# 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 Aug 29, 2015
CSV and MVC Notes 05/07/2015
View gist:d625e87df6053a28cd34
# There may be a few typos here and there and I also did not put up the Twilio Portion.
# ------------------------------------------------------------
# CSV
# ------------------------------------------------------------
require 'csv'
class Person