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
module Kernel | |
def require_relative_with_tco file | |
absolute_path = File.absolute_path file, __dir__ | |
realpath = File.realpath "#{absolute_path.chomp '.rb'}.rb" | |
if $LOADED_FEATURES.include? realpath | |
false | |
else | |
RubyVM::InstructionSequence.compile_file( | |
realpath, |
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
#First install the webp converter by this | |
sudo apt-get install webp | |
#go inside the directory where all images are there | |
#make sure all images are in RGB color mode, otherwise you will get error for CMYK images. | |
#Convert all images to RGB by this command (you should install ImageMagik to do that) | |
for f in *.jpg; do convert -colorspace RGB "$f" "${f}"; done | |
#finally convert all images to Webp format |
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
require 'benchmark' | |
require_relative 'lib/submatrix' | |
matrix = [ | |
[1, 1, 0, 0, 1, 1, 0, 0, 1, 0], | |
[1, 0, 0, 0, 1, 0, 0, 1, 0, 0], | |
[0, 0, 1, 1, 0, 1, 0, 1, 1, 1], | |
[1, 1, 1, 1, 1, 0, 0, 0, 0, 1], | |
[0, 0, 0, 1, 1, 1, 1, 0, 1, 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
DEFAULT_VALUES = { temperature: 10, altitude: 1200, pressure: 500 } | |
def fill_default_values(current_values) | |
{}.tap do |values| | |
DEFAULT_VALUES.each_key do | |
|key| values[key] = current_values[key] || DEFAULT_VALUES[key] | |
end | |
end | |
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
!/bin/bash | |
PID=`ps -eo pid,args | awk '/[[:digit:]]+ $1/ { print $1 }'` | |
echo $PID |
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
require 'minitest/autorun' | |
class MyError < StandardError | |
end | |
class MyExplorationsTest << Minitest::Test | |
def test_raises_my_exception | |
proc { fail MyError }.must_raise MyError | |
end | |
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
# abc=a^3+b^3+c^3 | |
i = 0 | |
max = 999 | |
while i <=999 | |
puts i.to_s.rjust(3,'0') if i == ((i /100) ** 3) + ((i % 100 / 10) ** 3) + ((i % 10) ** 3) | |
i +=1 | |
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
{ | |
"id": "38220-243858-3848303838", | |
"state": "enabled", | |
"url": "https://username:[email protected]", | |
"type": "new-block", | |
"block_chain": "bitcoin" | |
} |
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
require 'sinatra' | |
require 'json' | |
post '/' do | |
body = request.body.read | |
result = JSON.parse(body) | |
if result['payload']['type'] == 'address' | |
status(200) | |
body('OK\n') | |
else |
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 print_out_specific_level(level) | |
traverse_specific_level(root_node, 1, level) | |
end | |
def traverse_specific_level(node, current_level, desired_level) | |
if (current_level == desired_level) | |
puts node.val | |
return | |
end |
NewerOlder