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
// Design your class for inheritance and document it, otherwise forbid it using final | |
final class ChessAlgorithm { | |
. . . | |
} | |
/* Result: | |
Chess.java:6: Can't subclass final classes: class ChessAlgorithm | |
class BetterChessAlgorithm extends ChessAlgorithm { |
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
# This bypasses id == 1 condition and deletes all records | |
params[:id] = "1) OR 1=1--" | |
User.delete_all("id = #{params[:id]}") | |
# Produce: | |
# DELETE FROM "users" WHERE (id = 1) OR 1=1--) | |
# Bad | |
Project.where("name = '#{params[:name]}'") |
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
# Given an user | |
@user = Article.new(params[:user]) | |
# Bad | |
logger.debug "New user: #{@user.attributes.inspect}" | |
# Good | |
logger.debug "New user: #{@user.attributes.id}" |
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
# http://code.tutsplus.com/tutorials/mass-assignment-rails-and-you--net-31695 | |
# Given the mass asignment: | |
attrs = {:first => "John", :last => "Doe", :email => "[email protected]"} | |
user = User.new(attrs) | |
user.first #=> "John" | |
user.last #=> "Doe" | |
user.email #=> "[email protected]" |
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
curl http://10.229.48.35:8282/people \ | |
--request POST \ | |
--header "Content-Type: application/json" \ | |
--data-binary ' | |
{ | |
"focusset_id": "54760a5ae4b04f6a80bde81a", | |
"from_date": "1416729600000", | |
"to_date": "1424200529143", | |
"ekhoscore_data": { | |
"aug_weights": { |
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
val payload = """ | |
{ | |
aug_weights: { | |
interest: 0.20, | |
impact: 0.0, | |
emotion: 0.10, | |
opinion: 0.0 | |
}, | |
terms_and_weights: [ | |
{ |
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
{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"account": { | |
"type": "object", | |
"properties": { | |
"account_type": { "enum": [ "individual", "organization" ] | |
}, | |
"name": { "type": "string" }, | |
"email": { "type": "string", "format": "email" }, |
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
case class Pet(name: String, kind: String) | |
case class Owner(name: String, pets: List[Pet]) | |
implicit def toOwner(doc: foos.T) = Owner( | |
name = doc.as[String]("name"), | |
pets = doc.as[MongoDBList]("pets").map(_.asInstanceOf[BasicDBObject]).map { p => | |
Pet(p.as[String]("name"), p.as[String]("kind")) | |
} toList | |
) |
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
def listQueryHistogram(username: String, focussetId: String) = | |
(ekhoAuth(GET, Some(username), Some(focussetId)) & | |
params & | |
parameters('queries) & | |
detach()) | |
{ | |
// The first two are the values extracted by params and parameterers directives | |
(params, queries) => ctx => | |
val theList = queries.split(",").toList |
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.io.File | |
import sbt._ | |
import Keys._ | |
object EkhoBuild extends Build { | |
lazy val root = Project("root", file(".")).dependsOn(ekhoFramework) | |
// Github dependencies | |
lazy val ekhoFramework = RootProject( |