Skip to content

Instantly share code, notes, and snippets.

View saitgulmez's full-sized avatar

Mehmet Sait Gülmez saitgulmez

View GitHub Profile
@saitgulmez
saitgulmez / vector_cpp_stl.md
Created May 4, 2025 05:45 — forked from chizhang529/vector_cpp_stl.md
Essentials of Vectors in C++ STL

1. Initialization

  • Declaring an empty vector and then pushing values
// creates an empty vector
std::vector<int> vec;
// push values into vector
vec.push_back(10);
vec.push_back(20);
vec.push_back(30);
@saitgulmez
saitgulmez / pagination_in_rails.rb
Last active October 8, 2024 12:07
pagination in rails
# Install wll_paginate (https://github.com/mislav/will_paginate)
bundle add will_paginate
# controllers/users_controller.rb
class UsersController < ApplicationController
def index
@users = User.paginate(page: params[:page], per_page: 3)
end
end
var blake = require('blakejs')
const main = async () => {
const hex_value = "0a0b";
console.log(hex_value)
// Output: 0a0b
const buffer = Buffer.from(hex_value, 'hex')
console.log(buffer)
// Output: <Buffer 0a 0b>
OK, Let's begin. Hello, Everybody.
My name is Narihiro Nakamura.
Today, I'm talking about "Parallel worlds of CRuby's GC".
I'm very happy now, because I'm meeting attendee in rubyconf.
And, one of my dreams is to talk in rubyconf.
So, I'm very happy and exciting.
Today is my first presentation in English.
My English is not good.
@saitgulmez
saitgulmez / clean_code.md
Created November 28, 2022 14:32 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@saitgulmez
saitgulmez / script.rb
Last active November 23, 2022 11:55
Get block info at a provided block hash
require 'casper_network'
# We'll use this to connect to the Casper Network.
client = Casper::CasperClient.new('YOUR_CASPER_NETWORK_NODE_IP_ADDRESS')
# A block hash is a Digest over the contents of the block Header.
block_hash = "53943d39b0ea69dbdd3e255cfafbe0a3d610ccd0e83d86c83ee6d2f623b92e84"
block = client.chain_get_block(block_hash)
# How to access and print the Era ID in which this block was created.
@saitgulmez
saitgulmez / block.rb
Last active November 23, 2022 11:51
Get block and block members at a provided block hash
require 'casper_network'
# Following IP addres is taken from https://testnet.cspr.live/tools/peers
YOUR_CASPER_NETWORK_NODE_IP_ADDRESS = "65.108.73.113"
# We'll use this to connect to the Casper Network.
client = Casper::CasperClient.new(YOUR_CASPER_NETWORK_NODE_IP_ADDRESS)
block_hash = "53943d39b0ea69dbdd3e255cfafbe0a3d610ccd0e83d86c83ee6d2f623b92e84"
block = client.chain_get_block(block_hash)
# A Block object
puts block
@saitgulmez
saitgulmez / block_height.rb
Last active November 22, 2022 18:31
Get block info at a provided block height
require 'casper_network'
# Following IP addres is taken https://testnet.cspr.live/tools/peers
node_ip_address = "65.21.235.219"
client = Casper::CasperClient.new(node_ip_address)
block = client.get_block_by_height(1271722)
# A Block object
puts block
# To retrieve BlockHeader object
var blake = require('blakejs')
const main = async () => {
const input = "abc"
console.log(Buffer.from(input, 'hex'))
const array = Uint8Array.from(Buffer.from(input, 'hex'));
console.log("array is ",array)
// Output : Uint8Array(1) [171]
const byte_array = blake.blake2b(array, null, 32);
require 'blake2b'
input = "020e0000006361737065722d6578616d706c65130000006578616d706c652d656e7472792d706f696e7401000000080000007175616e7469747904000000e803000001050100000006000000616d6f756e7404000000e803000001"
key = Blake2b::Key.none
hex = Blake2b.hex(input, key, 32) # It does not give the same result that we got from js
body_uint8_array = [input].pack("H*").unpack("C*").inspect
body_hash_array = Blake2b.bytes(body_uint8_array, key, 32)
puts body_hash_array.pack("C*").unpack("H*").first