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
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <memory> | |
using namespace std; | |
class Possible { | |
vector<bool> _b; | |
public: | |
Possible() : _b(9, true) {} |
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
" Colemak stuff | |
nnoremap k h | |
nnoremap n j | |
nnoremap e k | |
nnoremap i l | |
nnoremap d v | |
nnoremap D V | |
nnoremap s d | |
nnoremap S D |
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
//swift | |
protocol Addable { | |
func add(lhs: Self, rhs: Self) -> Self | |
} | |
extension String: Addable { | |
func add(lhs: String, rhs: String) -> String { | |
return lhs + rhs | |
} |
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
/* | |
* Copyright (C) 2010 The Android Open Source Project | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
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
public protocol Apply {} | |
extension Apply where Self: Any { | |
//let f = Foo().apply { | |
// $0.foo = 10 | |
// $0.bar = "bar" | |
//} | |
public func apply(_ block: (inout Self) -> Void) -> Self { | |
var copy = self |
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
sealed class Either<out L, out R> { | |
companion object { | |
fun <L> left(left: L): Left<L, Nothing> = Left(left) | |
fun <R> right(right: R): Right<Nothing, R> = Right(right) | |
} | |
fun left(): L? = when (this) { | |
is Left -> this.l | |
is Right -> null |
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 MyTestClass { | |
companion object { | |
init { | |
// things that may need to be setup before companion class member variables are instantiated | |
} | |
// variables you initialize for the class just once: | |
val someClassVar = initializer() | |
// variables you initialize for the class later in the @BeforeClass method: |
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
//without phantom type | |
enum class Currency { JPY, THB } | |
data class Money(val amount: Double, val currency: Currency) | |
class IllegalCurrencyException : Throwable("Wrong currency") | |
fun convertJPYToTHB(jpy: Money): Money { | |
//check whether we have right format | |
when(jpy.currency) { | |
Currency.JPY -> { |
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
// Basic setup | |
interface Exp | |
data class Lit(val x: Int): Exp | |
data class Add(val x: Exp, val y: Exp): Exp | |
interface IntAlg<A> | |
{ | |
fun lit(x: Int): A | |
fun add(x: A, y: A): A |
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
interface SingleAssignType<T> { | |
operator fun getValue(thisRef: Any?, property: KProperty<*>): T | |
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) | |
} | |
class SingleAssign<T> : SingleAssignType<T> { | |
private var initialized = false | |
private var _value: Any? = null |