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
/* Functionality: | |
* -- Activate pumps on moisture low | |
* -- If photoresistor low, and valid hours of day, then turn lights on for 10 minutes | |
* -- If water level low, then blink lights | |
*/ | |
#include <Wire.h> | |
#include <DS3231.h> | |
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
private static class Vec { | |
int x, y; | |
public Vec(int x, int y) { this.x = x; this.y = y; } | |
public Vec add(Vec oth) { return new Vec(x+oth.x, y+oth.y); } | |
public Vec rot90CW() { return new Vec(y, -x); } | |
public int infDist(Vec oth) { return Math.max(x-oth.x, y-oth.y); } | |
public boolean equals.... | |
} | |
// Returns spiral pattern in a (2n+1) * (2n+1) array |
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
// Rounding operations (efficient when n is a power of 2) | |
// Round down to the nearest multiple of n | |
#define ROUNDDOWN(a, n) \ | |
({ \ | |
uint32_t __a = (uint32_t) (a); \ | |
(typeof(a)) (__a - __a % (n)); \ | |
}) | |
// Round up to the nearest multiple of n | |
#define ROUNDUP(a, n) \ | |
({ \ |
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
-------------------------- MODULE multi_user_wire -------------------------- | |
EXTENDS Integers, Sequences | |
CONSTANTS Users, Servers, Accounts | |
MAX_MONEY == 20 | |
AtMostOneAdminPerOrg(users, orgs) == {roles \in [users -> {"user","admin"}]: | |
\A x,y \in users: (roles[x] = "admin" /\ roles[y] = "admin") => x = y} |
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
{-# LANGUAGE AllowAmbiguousTypes, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, TypeApplications, UndecidableInstances #-} | |
class Lift' m a b where | |
lift' :: m a -> b | |
instance (Applicative m) => Lift' m a (m a) where | |
lift' = id | |
instance (Applicative m, Lift' m a b) => Lift' m (x -> a) (m x -> b) where | |
lift' f = lift' . ((<*>) f) |
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 Var: | |
def __init__(self, name): | |
self.name = name | |
def execute(self, bindings): | |
return bindings[self.name] | |
class ConstInt: | |
def __init__(self, val): |
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
Documentation | |
The behavior of the NormalDialog is interesting. The method displays a messagebox but, the contents of the message box are based around a total of 10 parameters. Here is an example: | |
NormalDialog(msg, DIALOG_OKAY, -1, -1, -1, 0, -1, 0, -1, 0); | |
The first input is a message with the data type of char, and the remainder of the parameters are integers. Each aspect of the function can be altered by changing those numbers. |
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
{-# LANGUAGE TypeOperators, GADTs, Strict #-} | |
module Main where | |
data (:+:) f g a = Inl !(f a) | Inr !(g a) | |
data A | |
data B | |
data Foo l where |
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
def normalize_interval(a, b): | |
if a <= b: return (a, b) | |
else: return (a, a) | |
# good version | |
def intersect(oth): | |
return interval(normalize_interval(min(self.hi, oth,hi), max(self.low, oth.low))) |
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 interval: | |
def init(low, hi): | |
self.low = low | |
self.hi = hi | |
# bad version | |
def intersect(oth): | |
if self.low <= oth.low: | |
if self.hi < oth.low: | |
return interval(0,0) |