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
import 'package:async/async.dart'; | |
import 'package:flutter_test/flutter_test.dart'; | |
void main() { | |
test("CancelableOperation with future", () async { | |
var cancellableOperation = CancelableOperation.fromFuture( | |
Future.value('future result'), | |
onCancel: () => {print('onCancel')}, | |
); |
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
superman 127.0.0.1 Kim whoami | |
database 127.0.0.1 Kim sleep 1 && echo "Database says Hello!" | |
localhost 127.0.0.1 Kim date |
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 Fixnum | |
# Runs a block, catching any exceptions matching the exceptions in the | |
# input parameters. After +self+ number of tries, the exception is | |
# re-raised and the attempts will terminate. | |
# | |
# @yield +self+ | |
# @param [Exception, …] exs Exceptions that will be caught and recovered from. | |
# @return Whatever the block returns. | |
def tries(*exs) | |
exs = [StandardError] if exs.empty? |
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 'rack' | |
class Object | |
def to_webapp | |
def self.call(env) | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func || :inspect, *attrs)] | |
end | |
self | |
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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |
# Activate the gem you are reporting the issue against. |
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 PriorityQueue | |
attr_reader :elements | |
def initialize | |
@elements = [nil] | |
end | |
def <<(element) | |
@elements << element | |
bubble_up(@elements.size - 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
class Fixnum | |
def each_bit | |
8.times do |p| | |
yield (self & 1 << p) >> p | |
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
require 'net/http' | |
require 'uri' | |
def download(url) | |
Thread.new do | |
thread = Thread.current | |
body = thread[:body] = [] | |
url = URI.parse url | |
Net::HTTP.new(url.host, url.port).request_get(url.path) do |response| |
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 'digest' | |
class ConsistentHashing | |
def initialize(nodes) | |
nodes.map { |node| add_node(node) } | |
end | |
def find_cache(key) | |
puts | |
hash = hash_value(key) |
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 CategoriesController < ApplicationController | |
include Behaveable::ResourceFinder | |
include Behaveable::RouteExtractor | |
# Response type. | |
respond_to :json | |
# Get categories. | |
# | |
# GET (/:categorizable/:categorizable_id)/categories(.:format) |