Skip to content

Instantly share code, notes, and snippets.

# typed: ignore
# Ruby 2.7 (Pattern Matching)
require 'sorbet-runtime'
class FizzBuzz
extend T::Sig
sig {params(n: Integer).void}
def self.check_number(n)
# typed: true
require 'sorbet-runtime'
class FizzBuzz
extend T::Sig
sig {params(n: Integer).void}
def self.check_number(n)
if n <= 0 then raise ArgumentError end
end
# typed: ignore
require_relative '../fizzbuzz'
describe 'FizzBuzz' do
it 'check_number' do
f = ->(n) { FizzBuzz.check_number(n) }
expect{f.(-1)}.to raise_error ArgumentError
expect{f.(0)}.to raise_error ArgumentError
expect{f.(1)}.to_not raise_error
end
# typed: true
# Ruby 2.6 (Function Composition, filter)
require 'sorbet-runtime'
class MailHeader
extend T::Sig
TEST_FILE_PATH = '/tmp/__mail_header_test_file__'
# typed: ignore
require_relative '../mail_header'
describe 'MailHeader' do
it 'split_header_body' do
f = ->(text) { MailHeader.split_header_body(text) }
expect{f.("abcdefghi")}.to raise_error ArgumentError
expect(f.("abc\r\n\r\ndef\r\n\r\nghi")).to eq ["abc", "def\r\n\r\nghi"]
end
#!/usr/bin/env julia
using HTTP
function print_usage()
println("Usage: send_chatwork token room_id body")
end
function make_chatwork_url(room_id::String)::String
"https://api.chatwork.com/v2/rooms/$room_id/messages"
@ykon
ykon / raw_input.rs
Created May 6, 2019 13:27
RawInput in Rust
/*
[dependencies]
widestring = "0.4.0"
lazy_static = "1.3.0"
[dependencies.winapi]
version = "0.3.7"
features = ["winuser", "winbase", "libloaderapi", "hidusage"]
*/
/*
javac --release 12 --enable-preview -Xlint:unchecked TestSwitchExp.java
java --enable-preview TestSwitchExp
*/
import java.util.stream.IntStream;
public class TestSwitchExp {
static class Tuple<X, Y> {
public final X x;
open System
open System.IO
open System.Text.RegularExpressions
let read_file (path:string): string option =
if (File.Exists path) then Some(File.ReadAllText path) else None
let split_header_body (text:string): (string*string) option =
match text.Split([|"\r\n\r\n"|], 2, StringSplitOptions.None) with
| [| header; body|] -> Some(header, body)
import java.nio.file._
object mail_header {
def read_file(path: String): Option[String] = {
val p = Paths.get(path)
if (Files.exists(p)) Some(new String(Files.readAllBytes(p))) else None
}
def split_header_body(text: String): Option[(String, String)] = {
text.split("\r\n\r\n", 2) match {