Skip to content

Instantly share code, notes, and snippets.

View hackrio1's full-sized avatar

Hackrio hackrio1

  • Hackrio
  • Gurugram
View GitHub Profile
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
#include <stdio.h>
union PersonUnion {
int height;
double weight;
};
struct PersonStruct {
int height;
double weight;
genesis_block_hash: 3495953456182427352
block1_hash: -554281952046316805
genesis_block_hash: 3220110016770526666
block1_parent_hash: 3495953456182427352
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)
# 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]
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;
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
def set_user
@user = current_user
end
class ApplicationController < ActionController::Base
before_action :authenticate_user
end
class Article < ApplicationRecord
belongs_to :user
validates :title, :text, presence: true
end