This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Details of Union | |
Height of person1_union: 1700 | |
Weight of person2_union: 74.230000 | |
Size of person1_union object: 8 | |
Size of person2_union object: 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
union PersonUnion { | |
int height; | |
double weight; | |
}; | |
struct PersonStruct { | |
int height; | |
double weight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
genesis_block_hash: 3495953456182427352 | |
block1_hash: -554281952046316805 | |
genesis_block_hash: 3220110016770526666 | |
block1_parent_hash: 3495953456182427352 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
genesis_block[1] = "Y paid $100 to X" | |
genesis_block_hash = get_hash_itself(genesis_block) | |
print "genesis_block_hash:", genesis_block_hash | |
print "block1_parent_hash:", get_parent_hash(block1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A block is stored as a tuple of | |
# (parent_hash, transactions, hash_itself) | |
def get_parent_hash(block): | |
return block[0] | |
def get_transactions(block): | |
return block[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merge sort - Code | |
#include <stdio.h> | |
// function to sort the subsection a[i .. j] of the array a[] | |
void merge_sort(int i, int j, int a[], int aux[]) { | |
if (j <= i) { | |
return; // the subsection is empty or a single element | |
} | |
int mid = (i + j) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlesController < ApplicationController | |
before_action :set_user | |
before_action :set_article, only: [:show, :edit, :update, :destroy] | |
# GET /articles/1 | |
# GET /articles.json | |
def index | |
@articles = @users.articles.all | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_user | |
@user = current_user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_action :authenticate_user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Article < ApplicationRecord | |
belongs_to :user | |
validates :title, :text, presence: true | |
end |