Skip to content

Instantly share code, notes, and snippets.

View razie's full-sized avatar

Razvan Cojocaru razie

View GitHub Profile
@razie
razie / scala-profiles.markdown
Created September 24, 2010 15:35
Scala abuses

Scala is a wonderful language, with a specification of a size comparable with that of Java. Overall, the specification is simpler than C++. Why then do some feel intimidated by its expressiveness?

Scala can generate complex constructs. There are some features of the language that, if not used properly, can negatively influence one's perception of its simplicity and generate a waste of many an hour of a frustrated developer.

Newcomers from simply typed, object-oriented, structured languages do not have a full grasp of all the features of scala and their effects or benefits, and they may be very surprised if others on their team use them.

One thing to have when starting or using scala is a readily available bible. I recommend "Programming in Scala", the .pdf version, an easily searcheable language reference.

The scala style guide is very good. Here we will describe the advanced features of the language, which are aimed at library-developers and should not b

@razie
razie / scalaskilset.markdown
Created December 9, 2010 17:42
Scala skill levels
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>com.ibm.mq.allclient</artifactId>
<version>${com.ibm.mq.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.mq</groupId>
<artifactId>jms</artifactId>
/**
* To run the Scala compiler programatically, we need to provide it with a
* classpath, as we would if we invoked it from the command line. We need
* to introspect our classloader (accounting for differences between execution
* environments like IntelliJ, SBT, or WebStart), and find the paths to JAR
* files on disk.
*/
final class ReplClassloader(parent: ClassLoader) extends ClassLoader(parent) with razie.Logging {
override def getResource(name: String): URL = {
// Rather pass `settings.usejavacp.value = true` (which doesn't work
grep LF.STOP.PAGE logs/log.log | grep -v "/ping" | sed 's/.*LF.STOP.PAGE .* \(.*\) took \([0-9]*\)ms.*/\2 \1/g' | sort -n -r --key=1 | sort -r --key=2 | uniq --skip-fields=1 | sort -b -n -r | head -20
object Sample2 {
val notificationStream : Stream[(String,String)] = Stream.empty
object db {
def findOrder(id:String) : Stream[{def accountId:String}] = Stream.empty
def findAccount(id:String) : Stream[{def email:String}] = Stream.empty
def updateAccount(id:Any) : Stream[Boolean] = Stream.empty
def updateOrder(id:Any) : Stream[Boolean] = Stream.empty
}
object email {
def send(id:String,n:String) : Stream[Boolean] = Stream.empty
import akka.actor.{Actor, Props}
import play.libs.Akka
object Sample {
case class MsgNotify()
case class MsgFindOrder(orderId: String)
case class MsgOrderFound(order: {def accountId: String})
case class MsgFindAccount(accountId: String)
case class MsgAccountFound(account: {def email:String})
@razie
razie / play-simple-logging.scala
Last active December 28, 2015 06:09
I do need to cleanup this code, it was written during stressful times...
/** customize some global handling errors */
object Global extends WithFilters(LoggingFilter) {
// EMAIL BACKOFF stuff
val ERR_DELTA1 = 5 * 60 * 1000 // 5 min
val ERR_DELTA2 = 6 * 60 * 60 * 1000 // 6 hours
val ERR_EMAILS = 5 // per DELTA2
var errEmails = 0 // sent per DELTA2
var lastErrorTime = System.currentTimeMillis - ERR_DELTA1 // time last error email went out - just one every 5 min, eh
var firstErrorTime = System.currentTimeMillis - ERR_DELTA2 // time first error email went out - just one every 5 min, eh
var lastErrorCount = 0 // time last error email went out - just one every 5 min, eh
def ping-me() = Action { implicit request =>
Ok(osusage)
}
def osusage = {
var s = ""
val osm: OperatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
for (method <- osm.getClass().getDeclaredMethods()) {
method.setAccessible(true);
@razie
razie / crash-course.scala
Created July 24, 2012 15:24
crash course to scala - looking for better ideas
//crash-course into scala: select the following defs and issue "run selection"
class Num (val i:Int) {
def + (other:Num) = new Num (this.i + other.i) // operators
override def toString : String = "Numero " + i.toString // inherit Java methods
override def equals (other:Any) = other match { // or override them
case n:Num => n.i == i
case _ => false // wildcard serves like a default case
}
}