This file contains hidden or 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
function maybePrint(x?: string) { | |
if (x != null) { | |
// we know that x will be a string in this scope | |
console.log(x); | |
} | |
} |
This file contains hidden or 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
interface Named { | |
name: string; | |
} | |
let x: Named; | |
let y = { name: "John", age: 42 }; | |
// This is OK because Y meets the interface requirements of Named | |
x = y; |
This file contains hidden or 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
# ... | |
expectation_mutex = Mutex.new | |
expect(client).to receive(:fetch_users) do |args| | |
expectation_mutex.synchronize do | |
expect(args).to eql(current_page) | |
end | |
# ... | |
end |
This file contains hidden or 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
it 'makes two requests to resolve the users when necessary' do | |
current_page = 1 | |
expectation_mutex = Mutex.new | |
expect(client).to receive(:fetch_users).exactly(2).times do |args| | |
expect(args).to eql(current_page) | |
current_page += 1 |
This file contains hidden or 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
it 'makes two requests to resolve the users when necessary' do | |
current_page = 1 | |
expectation_mutex = Mutex.new | |
expect(client).to receive(:fetch_users).exactly(2).times do |args| | |
expect(args).to eql(current_page) | |
current_page += 1 |
This file contains hidden or 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 SomeAPI | |
def fetch_users | |
prom = if only_need_to_fetch_one_page? | |
client.fetch_page(1).then { |res| res.fetch('users') } | |
else | |
promises = Concurrent::Promise.zip(client.fetch_page(1), client.fetch_page(2)) | |
promises.then do |first_page, second_page| | |
combine_results(first_page, second_page) | |
end |
This file contains hidden or 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 ThreadsafeMemoized | |
def initialize | |
@memoized = {} | |
@mutex = Support::ReentrantMutex.new | |
end | |
def fetch_or_store(key) | |
@memoized.fetch(key) do # only first access pays for synchronization | |
@mutex.synchronize do | |
@memoized.fetch(key) { @memoized[key] = yield } |
This file contains hidden or 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 'aws-sdk' | |
# This will create an engine mounted at your subdomain of choice. | |
# If you wanted it to be `kibana.example.com`, set KIBANA_SUBDOMAIN="kibana". | |
# The engine can be routed in Rails like so: | |
# Rails.application.routes.draw do | |
# constraints subdomain: ENV.fetch('KIBANA_SUBDOMAIN') do |
This file contains hidden or 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 | |
begin | |
require 'bundler/inline' | |
rescue LoadError => e | |
$stderr.puts 'Bundler version 1.10 or later is required.' | |
raise e | |
end | |
gemfile(true) do | |
source 'https://rubygems.org' |
This file contains hidden or 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 "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "activerecord", "5.0.0" | |
gem "sqlite3" | |
end | |
require "active_record" | |
require "minitest/autorun" |