Skip to content

Instantly share code, notes, and snippets.

View OlegIlyenko's full-sized avatar

ΘLΞG OlegIlyenko

View GitHub Profile
@OlegIlyenko
OlegIlyenko / min-max-usage.scala
Created March 27, 2010 01:49
minBy and maxBy for Traversable
println("Sorted: " + list.sortBy(_.balance))
println("Max: " + list.maxBy(_.balance))
println("Min: " + list.minBy(_.balance))
import io.Source
import scala.util.control.Breaks._
/**
* Scala TicTacToe game without any side effects
*
* Written in response to following post (which also contains task description):
* http://blog.tmorris.net/scala-exercise-with-types-and-abstraction/
*/
object TicTacToe {
@OlegIlyenko
OlegIlyenko / Build.scala
Created December 11, 2011 19:01
Publishing Pamflet with SBT and gh-pages (project/project/Build.scala)
import sbt._
object PluginDef extends Build {
override def projects = Seq(root)
lazy val root = Project("plugins", file(".")) dependsOn (ghpages, pamflet)
lazy val ghpages = uri("git://github.com/jsuereth/xsbt-ghpages-plugin.git")
lazy val pamflet = uri("git://github.com/n8han/pamflet-plugin#0.3.0")
}
@OlegIlyenko
OlegIlyenko / build.sbt
Created December 11, 2011 19:08
Publishing Pamflet with SBT and gh-pages (build.sbt)
import com.jsuereth.sbtsite.SiteKeys
// add all setting from the site plugin to the project
seq(site.settings: _*)
// add all setting from the ghpages plugin to the project
seq(ghpages.settings: _*)
// read-only git repository URI of the current project
git.remoteRepo := "git://github.com/OlegIlyenko/scaldi.git"
@OlegIlyenko
OlegIlyenko / create-gh-pages-branch.sh
Created December 11, 2011 19:46
Creating gh-pages branch in git repository
$ cd /path/to/fancypants
$ git symbolic-ref HEAD refs/heads/gh-pages
$ rm .git/index
$ git clean -fdx
import java.io.{FilterInputStream, InputStream}
class ProgressInputStream(in: InputStream, listener: Long => Unit) extends FilterInputStream(in) {
val NotificationThreshold = 8 * 1024;
var unnotifiedByteCount = 0
override def read() = {
val data = super.read()
if (data != -1) notify(1)
import math._
class ProgressListener(availableBytes: Long, tracker: Progress => Unit) extends Function1[Long, Unit] {
var transfered: Long = 0
val startTime = System.currentTimeMillis
def apply(bytesTransfered: Long) {
transfered += bytesTransfered
val elapsed = System.currentTimeMillis - startTime
val bpms = (transfered / max(elapsed, 1000)).toLong
import math._
case class Progress(percent: Int, size: Long, remains: Long, done: Long, bps: Long, elapsed: Long, estimated: Long) {
lazy val formattedMetrics= List(
"Progress: " + percent + "%",
"File size: " + formatSize(size),
"Downloaded: " + formatSize(done),
"Remains: " + formatSize(remains),
"Speed: " + (bps / 1024) + " kb/s",
"Elapsed: " + formatTime(elapsed),
import javax.swing.UIManager
import java.net.URL
import java.awt.Dimension
import java.io.Closeable
import swing._
object Downloader extends SimpleSwingApplication {
UIManager.getInstalledLookAndFeels
.filter(_.getName contains "Nimbus").headOption
package scaldi.keys
import math._
import swing._
import java.io.{Closeable, InputStream, FilterInputStream}
import javax.swing.UIManager
import java.net.URL
object Downloader extends SimpleSwingApplication {