Skip to content

Instantly share code, notes, and snippets.

/* 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>
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
@jkoppel
jkoppel / roundup.c
Created July 26, 2019 20:10
Roundup, rounddown
// 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) \
({ \
-------------------------- 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}
{-# 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)
class Var:
def __init__(self, name):
self.name = name
def execute(self, bindings):
return bindings[self.name]
class ConstInt:
def __init__(self, val):
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.
{-# 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
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)))
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)