Skip to content

Instantly share code, notes, and snippets.

@rbaron
rbaron / touch_sensor_hack.ino
Created March 9, 2021 20:42
A quick-and-dirty Arduino sketch for reading capacitive touch values.
#define N_SAMPLES 64
void setup()
{
Serial.begin(9600);
while (!Serial) delay(10);
}
void loop()
{
@rbaron
rbaron / gist:658361772457011be6eea0e061ae94c3
Created March 22, 2018 20:53
Differential privacy simulation
{
"cells": [
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib notebook\n",
"import collections\n",
@rbaron
rbaron / README.md
Created September 22, 2017 19:09
@ac bot

Md

@rbaron
rbaron / em_simple.py
Created June 16, 2016 22:05
EM example
"""
This script is an example of learning parameters of a Bayesian network
with hidden variables. The following Bayesian net is analyzed:
(hidden) (observable)
K -----------> A
Where K (knowledge) is not observable and A (answers), which depends on K, is.

Keybase proof

I hereby claim:

  • I am rbaron on github.
  • I am rbaron (https://keybase.io/rbaron) on keybase.
  • I have a public key whose fingerprint is B22D 7692 7828 E780 B3C4 8A20 28F6 64EB A5ED B223

To claim this, I am signing this object:

@rbaron
rbaron / prime_stream.py
Last active October 27, 2015 14:09
Two ways of generating an infinite stream of prime numbers via sieve of Eratosthenes
import itertools
def take(n, iterable):
return list(itertools.islice(iterable, n))
def enum_integers(start):
return itertools.count(start)
def is_not_divisible_by(n, which):
return n%which != 0
@rbaron
rbaron / question.scala
Created August 31, 2015 18:32
Type parameter question
trait Indiv[V <: Indiv[V]] {
val fitness: Double
def reproduce(other: V): V
}
class RealIndiv[V](override val fitness: Double) extends Indiv[V] {
override def reproduce(other: V) = new RealIndiv(fitness + other.fitness)
// ^ Cannot resolve symbol fitness (on `other.fitness`)
}
@rbaron
rbaron / inherit.scala
Created August 28, 2015 14:11
Inheritance question
trait Individual[T] {
def mate(other: Individual[T]): Individual[T]
}
class Person[T] extends Individual[T] {
// This "overrides nothing":
override def mate(other: Person[T]): Person[T] = new Person[T]()
}
@rbaron
rbaron / TweetSet.scala
Created May 28, 2015 21:31
week03 progfun solution
package objsets
import common._
import TweetReader._
/**
* A class to represent tweets.
*/
class Tweet(val user: String, val text: String, val retweets: Int) {
override def toString: String =