Skip to content

Instantly share code, notes, and snippets.

View irridescentrambler's full-sized avatar
🤓
Exploring

Nikhil Mohadikar irridescentrambler

🤓
Exploring
View GitHub Profile
require 'net/http'
require 'uri'
require 'async'
require 'benchmark'
bm = Benchmark.measure("Asynchronous flow") do
Async do
results = 21.times.map do |url|
Async do
Net::HTTP.get_response(URI("https://dog.ceo/api/breeds/image/random"),)
worker = nil
manager = Fiber.new do |work_for_manager|
puts "Manager starting the work"
puts "Doing the work...(Manager)"
puts work_for_manager
puts "Ending the work..(Manager)"
worker.transfer("Do this now - Manager")
puts "Approving - Manager"
puts "Manager logging off"
fiber = Fiber.new do
n = 1
while n <= 30 do
Fiber.yield (1..n).inject(&:*)
n = n + 1
end
end
while fiber.alive?
puts fiber.resume
import { React } from 'react';
import Axios from 'axios';
class Demo extends React.Component{
initialize(){
this.state = {
userInput: nil,
employees: [],
status: nil
}
class Human
attr_accessor :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
"#{first_name} #{last_name}"
[1,2,3,4,5].method(:length).source_location
#=> nil
"Ruby".method(:concat).source_location
#=> nil
class Array
def subset?(sub_array)
sub_array.each do |element|
return false unless self.include?(element)
module Configurable
def is_a
wrapper(true)
end
def is_not_a
wrapper(false)
end
private
require 'active_record'
ActiveRecord::Base.method(:new).owner
#=> ActiveRecord::Inheritance::ClassMethods
ActiveRecord::Base.method(:create).owner
#=> ActiveRecord::Persistence::ClassMethods
ActiveRecord::Base.method(:update).owner
#=> ActiveRecord::Querying
# A simple class in Ruby
class Human
def introduce
"Hi, I am a #{self.class.name}"
end
end
Human.ancestors
#=> [Human, Object, Kernel, BasicObject]
# Object is present in Human class's ancestor tree.
class A
end
class B < A
end
class C < B
end
A.descendants