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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
public static class ContainerExtensions | |
{ | |
public static IEnumerable<(int, T)> Enumerate<T>(this IEnumerable<T> enumerable) | |
{ | |
int index = 0; | |
foreach (T v in enumerable) |
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
# Check overlap of range [a1, a2) and range [b1, b2), where None indicates infinity. | |
def ranges_intersect(a, b): | |
# Make sure that a starts before or at b. | |
if b[0] is None or (a[0] is not None and b[0] < a[0]): | |
a, b = b, a | |
# If b starts before a ends, then there is an intersection. | |
return b[0] is None or a[1] is None or b[0] < a[1] |
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
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
public static class TaskExtensions | |
{ | |
// Forward result of task if it completes before given timeout. Otherwise, | |
// return default(T). The original task will remain running until it completes. | |
public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout) | |
{ |
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
choose: | |
- conditions: | |
- condition: or | |
conditions: | |
- condition: state | |
entity_id: input_select.phase | |
state: Sova | |
- condition: state | |
entity_id: input_select.phase | |
state: Borta |
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
using System; | |
using System.Linq; | |
using System.Text.RegularExpressions; | |
// Class for dealing with person identity numbers. There are three | |
// overall types of identities for a person: | |
// - Personnummer. This is the standard number assigned to any person | |
// who is accepted as a Swedish citizen. It's unique and kept for life. | |
// - Samordningsnummer. This is assigned to someone who is a | |
// registered visitor/occupant in Sweden and needs an identifier. |
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
import java.io.IOException; | |
import java.io.UncheckedIOException; | |
public class Exceptions { | |
private Exceptions() | |
{ | |
} | |
private static class WrappedCheckedException extends RuntimeException { | |
public static final long serialVersionUID = 1L; |
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
use cgmath::prelude::*; | |
use cgmath::{vec2, vec3, ElementWise, EuclideanSpace, InnerSpace, SquareMatrix}; | |
use crossbeam::thread; | |
use image::{ImageBuffer, RgbImage}; | |
use reduce::Reduce; | |
use std::cmp::{PartialOrd}; | |
use std::f64; | |
use rand::Rng; | |
use std::sync::Mutex; |