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
var flags = fcntl(reader.fileDescriptor, F_GETFL) | |
_ = fcntl(reader.fileDescriptor, F_SETFL, flags | O_NONBLOCK) | |
public var nonBlockingAvailableData: Data? { | |
return self.__readDataOfLength(Int.max, untilEOF: false) | |
} | |
internal func __readDataOfLength(_ length: Int, untilEOF: Bool) -> Data? { | |
let _closed: Bool = false | |
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
#if os(Linux) | |
import Glibc | |
#else | |
import Darwin.C | |
#endif | |
import Foundation | |
var counter = 0 | |
var messages = Array<String>() | |
FileHandle.standardInput.readabilityHandler = { filehandler in |
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
extension Either : Decodable where Right: Decodable, Left == Error { | |
public init(from decoder: Decoder) throws { | |
do { | |
let container = try decoder.singleValueContainer() | |
let value = try container.decode(Right.self) | |
self = .right(value) | |
} catch { | |
self = .left(error) | |
} | |
} |
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
defmodule Tiled.Utils.Decoder do | |
@moduledoc false | |
defmodule InternalDecoder do | |
@moduledoc false | |
defmacro __before_compile__(_env) do | |
quote do | |
@spec decode_key_value({:type, String.t()}) :: atom() | nil | |
defp decode_key_value({:type, ""}), do: nil | |
defp decode_key_value({:type, type}) when is_binary(type), do: type |> String.to_atom() |
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
defmodule Utils.TypedStruct do | |
@moduledoc """ | |
Define module with struct and typespec, in single line. | |
#### Thus | |
``` | |
alias Utils.TypedStruct | |
defmodule User do | |
use TypedStruct, name: String.t | |
deftypedstruct Phone, numbers: list(integer) |
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
defmodule Drawille.Braille do | |
@moduledoc """ | |
Module for a braille code. | |
""" | |
@braille_offset 0x2800 | |
@doc """ | |
You can get "braille byte" by pixel_map. | |
pixel map to n-th bits: |
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
const randomError$ = Rx.Observable | |
.create(observer => { | |
if (Math.random() < 0.5) { | |
observer.next("success") | |
} | |
else { | |
observer.error("FAILED REQUEST") |
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
// | |
// ViewController.swift | |
// iOSDemo | |
// | |
// Created by Seivan Heidari on 17/05/04. | |
// | |
// | |
import UIKit | |
import StateKit |
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
self.store.state | |
.distinctUntilChanged() | |
.subscribe { if let state = $0.element { | |
print(state) | |
print("\n") | |
self.view.subviews | |
.flatMap { $0 as? UIButton } | |
.forEach { | |
$0.isEnabled = state.isLoading == false |
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
# This demonstrates that, when using async/await, a crash in the task will crash the caller | |
defmodule Tasker do | |
def good(message) do | |
IO.puts message | |
end | |
def bad(message) do | |
IO.puts message | |
raise "I'm BAD!" | |
end |