Skip to content

Instantly share code, notes, and snippets.

Seivan Heidari seivan

Block or report user

Report or block seivan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
seivan / BitSetPerformanceTests.swift
Created Jul 27, 2018
`BitSet / BitVector / BitArray` using `UnsafeMutablePointer` instead of `Array<T>`
View BitSetPerformanceTests.swift
import XCTest
import Foundation
final class Ref {
var value : UnsafeMutablePointer<Int>
init(_ v : UnsafeMutablePointer<Int>) {value = v}
deinit {
seivan / NonBlockingRead.swift
Last active Jul 4, 2018
Nonblocking availableData on FileDescriptor incase you've set the O_NONBLOCK flag.
View NonBlockingRead.swift
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
View statefulprocess.swift
#if os(Linux)
import Glibc
import Darwin.C
import Foundation
var counter = 0
var messages = Array<String>()
FileHandle.standardInput.readabilityHandler = { filehandler in
View Either+Decodable.swift
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)
View decode.ex
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()
View TypedStruct.ex
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)
View drawing.ex
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:
seivan / sample.ts
Created Mar 20, 2018
Redux with RX
View sample.ts
const randomError$ = Rx.Observable
.create(observer => {
if (Math.random() < 0.5) {"success")
else {
observer.error("FAILED REQUEST")
View stateless.swift
// ViewController.swift
// iOSDemo
// Created by Seivan Heidari on 17/05/04.
import UIKit
import StateKit
View sample.swift
.subscribe { if let state = $0.element {
.flatMap { $0 as? UIButton }
.forEach {
$0.isEnabled = state.isLoading == false
You can’t perform that action at this time.