Skip to content

Instantly share code, notes, and snippets.

View frozenspider's full-sized avatar

Alex Abdugafarov frozenspider

View GitHub Profile
@frozenspider
frozenspider / gist:9069233
Last active August 29, 2015 13:56
ProposalMapping definition options
new ProposalMapping(
executionDate = None,
commencementDate = None,
expirationDate = None,
freeMonths = None,
leaseTerm = None
)
new ProposalMapping(
@frozenspider
frozenspider / gist:9135498
Created February 21, 2014 14:46
class ProposalMapping
/**
* Entity representing mapping of comp proposal from XLS column names.
*
* @author FS
*/
// Please preserve attribute order when defining a new mapping
class ProposalMapping(
// Date
val executionDate: Option[String],
val commencementDate: Option[String],
@frozenspider
frozenspider / gist:9376005
Last active August 29, 2015 13:57
Different formats of one-liners
// Ugly one-liner: type is in the middle of the line, implementation takes less than half a line
// Pain!
implicit class RichSsWorkbook(wb: Workbook) {
def apply(i: Int): Sheet = wb.getSheetAt(i)
def bytes: Array[Byte] = {
val baos = new ByteArrayOutputStream
wb.write(baos)
baos.toByteArray
}
@frozenspider
frozenspider / Parsers.scala
Last active August 29, 2015 13:57
trait Parsers
trait Parsers {
type Elem
type Input = Reader[Elem]
sealed abstract class ParseResult[+T] {
...
}
case class Success[+T](result: T, override val next: Input) extends ParseResult[T] {
...
}
trait A {
val a: Int
}
trait B extends A {
println(a)
}
trait C extends A {
override val a: Int = 10
@frozenspider
frozenspider / comp-proposal-dao-query3.sql
Last active August 29, 2015 13:58
comp-proposal-dao-query3
SELECT status_temp.id FROM (
SELECT temp_batch.original_id as id, temp_batch.validation_errors, COUNT(temps_enabled.id), COUNT(temps_disabled.id)
FROM comp_proposal_raw_temp_batch temp_batch
LEFT OUTER JOIN comp_proposal_raw temps_enabled
ON temps_enabled.temp_batch_id = temp_batch.id AND temps_enabled.dont_integrate = 0
LEFT OUTER JOIN comp_proposal_raw temps_disabled
ON temps_disabled.temp_batch_id = temp_batch.id AND temps_disabled.dont_integrate = 1
GROUP BY temp_batch.original_id
HAVING (COUNT(temps_enabled.id) = 0 AND COUNT(temps_disabled.id) > 0) OR temp_batch.validation_errors > 0
) status_temp
@frozenspider
frozenspider / slick-queries.sql
Created April 11, 2014 12:04
Slow and fast queries
# Generated by Slick (select terms optimized for clarity)
# Takes 47034 ms
SELECT *
FROM (
SELECT x281.id
FROM `comp_proposal_raw_batch_comp_proposal_raw` x282, `comp_proposal_raw` x281
WHERE (x282.`comp_proposal_raw_batch_proposals_id` = 4936) AND (x281.`id` = x282.`comp_proposal_raw_id`)
) x187
INNER JOIN (
SELECT *
@frozenspider
frozenspider / merge-and-rebase-history.txt
Last active August 29, 2015 14:06
Merge and rebase history
Merge:
z
|\
| g
x | |
| * |
| | f
| * |
| * |
@frozenspider
frozenspider / gist:b84eba656aea7a077c9b
Last active August 29, 2015 14:18
GORM/Hibernate associations test
import test.*
Parent.withNewSession {
Parent.withNewTransaction {
def parent = new Parent()
.addToChildren(new Child(name: "a"))
.addToChildren(new Child(name: "b"))
.addToChildren(new Child(name: "c"))
.save(failOnError: true)
}
@frozenspider
frozenspider / self-recursive-type-failure.scala
Last active November 21, 2015 21:24
self-recursive-type-failure.scala
trait Foo { self =>
type SelfType <: Foo {
type SelfType = self.SelfType
}
}
// SelfType points to its child type
trait FooExtLvl1 extends Foo {
type SelfType = FooExtLvl2
}