Skip to content

Instantly share code, notes, and snippets.

View dcbriccetti's full-sized avatar

Dave Briccetti dcbriccetti

View GitHub Profile
private Vector3 EnemyMovement(Transform closestUnit, Transform enemy) {
Vector3 enemyToUnit = closestUnit.position - enemy.position;
int maxManhattanDistancePerMove = 3;
int xDirection = Math.Sign(enemyToUnit.x);
int zDirection = Math.Sign(enemyToUnit.z);
int xSteps = (int) Math.Min(maxManhattanDistancePerMove, Math.Abs(enemyToUnit.x));
int stepsLeft = maxManhattanDistancePerMove - xSteps;
int zSteps = (int) Math.Min(stepsLeft, Math.Abs(enemyToUnit.z));
int dx = xDirection * xSteps;
int dz = zDirection * zSteps;
@dcbriccetti
dcbriccetti / ShareTime.scala
Created June 22, 2018 06:49
Scala.js program to track time with students, work in progress
package com.davebsoft.shrtime
import org.querki.jquery._
import org.scalajs.dom
import scala.math.BigDecimal.RoundingMode.HALF_UP
object ShareTime {
private var students = Seq[Student]()
C = 0.36 # uF
R1 = 1000 # Ohms
def analog_read():
return 10000
def read_resistance():
n = 10
// Sketch for a servo that turns with the light intensity
// See video demo at https://youtu.be/BSZc9sFR4vs
#include <Servo.h>
const Servo myServo;
const int lightSensor = A0;
const int red = 7;
const int green = 8;
const int speaker = 6;
@dcbriccetti
dcbriccetti / Runways.scala
Last active April 13, 2017 06:31
Simplify this Scala for expression? Each row of runways.tsv will generate either one or two Runway objects. I don’t like the flatten.flatten.
package flying
import scala.io.Source
case class Runway(airportId: String, runwayName: String, length: Int, surface: String)
class Runways {
/** Runways data from http://ourairports.com/data/, converted from csv to tsv with a spreadsheet program */
private val source = Source.fromFile("/Users/daveb/Documents/Flying/data/runways.tsv")
val runways = (
@dcbriccetti
dcbriccetti / parent_filters.py
Created August 15, 2016 07:26
Scala functional enthusiasm ruining my Python code?
def passthrough_filter(parents):
return filter(lambda _: True, parents)
def random_subset_filter(parents):
return filter(lambda _: random.random() < .15, parents)
def upcoming_filter(parents):
return filter(lambda parent: parent.has_upcoming, parents)
def upcoming_wanted_filter(parents):
@dcbriccetti
dcbriccetti / sieve
Created July 3, 2015 21:00
Sieve of Eratosthenes is faster with list than with numpy.array
import math
import numpy
from timeit import timeit
HIGHEST = 100000
ARRAY_LEN = HIGHEST + 1 # For 0
def make_sieve():
sieve = numpy.ones(ARRAY_LEN)
mark_composites(sieve)
return sieve
/* Display the numbers from 1 to 100 that are not divisible by both
4 and 7, but for those numbers divisible by 4, show ÷4 instead, and
for those divisible by 7, show ÷7 instead. */
object Solution1 extends App {
println(
(1 to 100 map(n => {
def divBy(div: Int) = n % div == 0
(divBy(4), divBy(7)) match {
case (false, false) => Some(n)
@dcbriccetti
dcbriccetti / gist:b70a7ff65541d79c467d
Last active August 29, 2015 14:16
Can you rewrite this to produce “combinations” for any nonzero value of “numDice”? (This is mostly academic curiosity.)
val combinations: Seq[Seq[Int]] = numDice match {
case 1 => for (a <- 1 to numSides) yield Seq(a)
case 2 => for (a <- 1 to numSides; b <- 1 to numSides) yield Seq(a, b)
case 3 => for (a <- 1 to numSides; b <- 1 to numSides; c <- 1 to numSides) yield Seq(a, b, c)
}
@dcbriccetti
dcbriccetti / gist:da05c00e4ae6d9afdef7
Last active August 29, 2015 14:13
An excerpt from Dave Briccetti’s first non-trivial Minecraft mod, inspired by Devoxx4kids Sharp Snowballs: https://github.com/devoxx4kids/materials/tree/master/workshops/minecraft
class SharpSnowballArray {
@SubscribeEvent
def replaceSnowballWithArrow(event: EntityJoinWorldEvent) {
val entity = event.entity
val world = entity.worldObj
entity match {
case snowball: EntitySnowball if ! world.isRemote =>
-2 to 2 foreach(xOff => {
-2 to 2 foreach (yOff => {