Skip to content

Instantly share code, notes, and snippets.

@sebnozzi
sebnozzi / pubnub-chat-10-lines.html
Created April 16, 2012 20:14
PubNub Chat in 10 lines
<div pub-key="..." sub-key="..." ssl="off" ...></div>
<script src="http://cdn.pubnub.com/pubnub-3.1.min.js"></script>
Enter Chat and press enter
<div><input id="input" value="you-chat-here" /></div>
Chat Output
<div id="output"></div>
<script>
@sebnozzi
sebnozzi / gist:2401308
Created April 16, 2012 20:30
PubNub Chat Demo CSS
#input {
font-size: 20px;
line-height: 20px;
}
#output, #input {
border-radius: 4px 4px 4px 4px;
box-shadow: 0 0 30px #EEEEEE inset;
margin: 10px;
padding: 10px;
@sebnozzi
sebnozzi / FizzBuzz.scala
Last active December 12, 2015 00:18
This is my "boring", "conservative", verbose, "my momma should grasp it" version of FizzBuzz...
object FizzBuzz extends App {
implicit class MyInt(thisNumber: Int) {
def isDivisibleByOrHasDigit(other: Int) = { isDivisibleBy(other) || hasDigit(other) }
def isDivisibleBy(other: Int) = (thisNumber % other == 0)
def hasDigit(c: Char): Boolean = thisNumber.toString.contains(c)
def hasDigit(x: Int): Boolean = {
assert(x >= 0 && x < 10, s"Number should be 1 digit long (found: $x)")
hasDigit(x.toString.head)
}
@sebnozzi
sebnozzi / RoboTest.scala
Last active December 17, 2015 18:29 — forked from anonymous/gist:4639734
Scala (2.10) version of the basic iOS app example of RoboVM: http://www.robovm.org/docs.html#ios-example
import org.robovm.cocoatouch.coregraphics._
import org.robovm.cocoatouch.foundation._
import org.robovm.cocoatouch.uikit._
object Utils {
import scala.language.implicitConversions
implicit class RichUIControl(control: UIControl) {
@sebnozzi
sebnozzi / 0-calendar.rb
Last active December 22, 2015 16:29
Exploring code transformation from Ruby to Scala. Taken from http://rosettacode.org/wiki/Calendar#Ruby . Taking Ruby as the original version, I want to show that it's possible to write more or less the same code in Scala. Except for the fact that Ruby comes with more "batteries included" than the JDK/Scala.
require 'date'
# Creates a calendar of _year_. Returns this calendar as a multi-line
# string fit to _columns_.
def cal(year, columns)
# Start at January 1.
#
# Date::ENGLAND marks the switch from Julian calendar to Gregorian
# calendar at 1752 September 14. This removes September 3 to 13 from
@sebnozzi
sebnozzi / toRoman-terse.scala
Created September 10, 2013 10:53
In the spirit of this article ( http://java.dzone.com/articles/merits-verbosity-and-flaws ) I wanted to re-write the implementation in a more verbose and readable fashion. Even if the result is not a cool one-liner ;-)
def toRoman( v:Int ) : String = {
val romanNumerals = List(1000->"M",900->"CM",500->"D",400->"CD",100->"C",90->"XC",
50->"L",40->"XL",10->"X",9->"IX",5->"V",4->"IV",1->"I")
var n = v
romanNumerals.foldLeft(""){(s,t) => {val c = n/t._1; n = n-t._1*c; s + (t._2 * c) } }
}
@sebnozzi
sebnozzi / TicTacToe.scala
Last active December 22, 2015 20:39
A TicTacToe implementation. Result of a TDD practice session (solo).
package com.sebnozzi.katas.tictactoe
object TicTacToe {
sealed class Player
case object O extends Player
case object X extends Player
case class Board(state: State = State()) {
@sebnozzi
sebnozzi / hangman-frames.scala
Created November 7, 2013 15:04
Frames for a progressing Hangman game. In case we need this for a Dojo.
import scala.collection.mutable.Buffer
val frames = Buffer[String]()
frames += """
> _______
> |/ |
> |
> |
> |
@sebnozzi
sebnozzi / PlayBrowserSpec.scala
Last active November 8, 2016 02:15
How to integrate ScalaTest (FlatSpec) with Play
import org.scalatest.BeforeAndAfterAll
import org.openqa.selenium.WebDriver
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.scalatest.FlatSpec
import play.api.test.TestServer
import org.scalatest.Matchers
import play.api.test.Helpers
import org.scalatest.selenium.WebBrowser
import play.api.test.FakeApplication
case class GreetingEvent(msg: String)
class Greeter extends Publisher[GreetingEvent] {
def greet(msg:String) = {
println("Firing event")
publish(GreetingEvent(msg))
}
}
class GreetingSubscriber(name: String)