Skip to content

Instantly share code, notes, and snippets.

View flmendes's full-sized avatar

Flávio Luiz Mendes flmendes

View GitHub Profile
@flmendes
flmendes / UndertowServer.java
Created August 22, 2017 04:07 — forked from vmarcinko/UndertowServer.java
Undertow-Spring MVC integration
package vmarcinko.undertow;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.PathHandler;
import io.undertow.server.handlers.RedirectHandler;
import io.undertow.server.handlers.resource.FileResourceManager;
import io.undertow.servlet.Servlets;
import io.undertow.servlet.api.DeploymentInfo;

10 Scala One Liners to Impress Your Friends

Here are 10 one-liners which show the power of scala programming, impress your friends and woo women; ok, maybe not. However, these one liners are a good set of examples using functional programming and scala syntax you may not be familiar with. I feel there is no better way to learn than to see real examples.

Updated: June 17, 2011 - I'm amazed at the popularity of this post, glad everyone enjoyed it and to see it duplicated across so many languages. I've included some of the suggestions to shorten up some of my scala examples. Some I intentionally left longer as a way for explaining / understanding what the functions were doing, not necessarily to produce the shortest possible code; so I'll include both.

1. Multiple Each Item in a List by 2

The map function takes each element in the list and applies it to the corresponding function. In this example, we take each element and multiply it by 2. This will return a list of equivalent size, compare to o

@flmendes
flmendes / sniff.txt
Created September 30, 2015 20:38 — forked from manifestinteractive/sniff.txt
A friendly formatter for curl requests to help with debugging.
\n
============= HOST: ==========\n
\n
local_ip: %{local_ip}\n
local_port: %{local_port}\n
remote_ip: %{remote_ip}\n
remote_port: %{remote_port}\n
\n
======= CONNECTION: ==========\n
\n
{
"color_scheme": "Packages/Color Scheme - Default/Monokai Bright.tmTheme",
"ensure_newline_at_eof_on_save": true,
"file_exclude_patterns":
[
"*.DS_store",
"*.gem",
"*.gz",
"*.jar",
"*.sassc",
@flmendes
flmendes / screencap.sh
Created February 18, 2014 21:39
A screen capture with a Scala script
#!/bin/sh
exec scala -savecompiled "$0" "$@"
!#
import java.awt._
import java.io._
import javax.imageio.ImageIO
if (args.length != 1) {
println(" Usage: script filename")
package core.dao
import play.api.Logger
import reactivemongo.core.commands.LastError
import reactivemongo.core.errors.DatabaseException
import scala.concurrent.Future
import core.db.MongoHelper
import core.exceptions._
package daos
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import play.api.Play.current
import play.modules.reactivemongo._
import reactivemongo.api._
import reactivemongo.api.indexes._
import reactivemongo.bson._
import reactivemongo.bson.handlers.BSONReader
// simple example of the cake pattern
// abstract DAO trait
trait Repository[A, B]{
// saves an entity, returns an ID
def save(entity: A): B
// more features..
}
trait RdbmsRepository extends Repository[MyUserCaseClass, Long]{
/*********************************************************
* Setup Domain object, repositories and service objects *
********************************************************/
// Identity.scala
case class Identity(id: Int = 0, var slug: String, var email: String, references: Symbol)
// IdentityRepostiory.scala: my interface that isolates concrete instances
trait IdentityRepository {
def findBySlug(slug: String): Option[Identity]
def findByEmail(email: String): Option[Identity]
@flmendes
flmendes / README.md
Created February 5, 2013 04:31 — forked from keikubo/README.md

Nginx + Unicorn for Rails on Rackhub

Description:

This script enables you to launch your Rails application in production environment (port:80) with Nginx and Unicorn.

Installation:

Please make sure that your Gemfile in your rails application includes unicorn.