This file contains hidden or 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
| require 'yaml' | |
| require 'twitter' | |
| yaml = YAML.load_file('twitter.yaml') | |
| $client = Twitter::REST::Client.new do |config| | |
| config.consumer_key = yaml["consumer_key"] | |
| config.consumer_secret = yaml["consumer_secret"] | |
| config.access_token = yaml["token"] | |
| config.access_token_secret = yaml["secret"] |
This file contains hidden or 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
| require "serialport" | |
| require "net/http" | |
| require "uri" | |
| port_str = "/dev/tty.usbmodem1421" | |
| baud_rate = 9600 | |
| data_bits = 8 | |
| stop_bits = 1 | |
| parity = SerialPort::NONE | |
This file contains hidden or 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
| object scratch { | |
| type SentenceAnagram = Set[String] | |
| type SolutionSpace = Set[SentenceAnagram] | |
| type CharacterCounts = Map[Char, Int] | |
| def frequencyCount(word: String): CharacterCounts = { | |
| val grouped: Map[Char, String] = word.toLowerCase.replaceAll("[^a-z]", "").groupBy(c => c) | |
| grouped.map((pair: Tuple2[Char, String]) => (pair._1, pair._2.length)) | |
| } |
This file contains hidden or 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
| function Card(face, suit) { | |
| this.face = face; | |
| this.suit = suit; | |
| // Cheap to_string function | |
| this.to_s = function() { | |
| return "The " + face + " of " + suit; | |
| } | |
| } |
This file contains hidden or 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
| object Langton extends App { | |
| // TODO - make infinite vectors... | |
| type Grid = Vector[Vector[Boolean]] | |
| case class Ant(pos: (Int, Int), direction: Symbol) { | |
| // If current position is white (false), move right 1 square | |
| // If position is black (true), move left | |
| def move(grid: Grid): Ant = { |
This file contains hidden or 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.awt.{Color, Dimension, Graphics2D} | |
| import javax.swing.JPanel | |
| import scala.annotation.tailrec | |
| import scala.collection.mutable.ListBuffer | |
| import scala.swing.MainFrame | |
| import scala.util.Random | |
| class City (val x : Double, val y : Double, val name : String) { | |
| def distanceTo (c : City) : Double = { | |
| Math.sqrt((this.x - c.x) * (this.x - c.x) + (this.y - c.y) * (this.y - c.y)) |
This file contains hidden or 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 scala.io.Source | |
| import java.io.File | |
| import java.util.Arrays | |
| import scala.collection.mutable.ArrayBuffer | |
| import scala.collection.immutable.HashMap | |
| import scala.annotation.tailrec | |
| /** | |
| * Alice in Markov Chains for West London Hack Night | |
| * |
This file contains hidden or 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
| object Compiler extends Application { | |
| val program = "++++++++++" + | |
| "[" + | |
| ">+++++++" + | |
| ">++++++++++" + | |
| ">+++" + | |
| ">+" + | |
| "<<<<-" + | |
| "]" + |
This file contains hidden or 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
| object Solver extends App{ | |
| case class Puzzle (values: Vector[Vector[Option[Int]]]) { | |
| def printState { | |
| for (row <- values) { | |
| println((for (cell <- row) yield { | |
| cell match { | |
| case None => "_" | |
| case Some(i) => i | |
| } |
This file contains hidden or 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
| object Voronoi extends App { | |
| case class Point(x: Int, y: Int) | |
| val pubs: List[Point] = List(Point(1,4), Point(2,1), Point(4,3)) | |
| def findDist(start: Point, pub: Point): Int = { | |
| Math.abs(start.x - pub.x) + Math.abs(start.y - pub.y) | |
| } | |
NewerOlder