Skip to content

Instantly share code, notes, and snippets.

@amirkarimi
amirkarimi / sms.wsdl
Created December 18, 2014 11:06
Sample WSDL for Scalaxb
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:s="http://www.w3.org/2001/XMLSchema" targetNamespace="http://SMSBox.gateway.webservice.sspk.co.ir/" xmlns:tns="http://SMSBox.gateway.webservice.sspk.co.ir/" name="SMSBoxImplementationService">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://SMSBox.gateway.webservice.sspk.co.ir/">
<s:element name="Send">
<s:complexType><s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Auth" type="tns:Auth" />
<s:element minOccurs="1" maxOccurs="1" name="Recipients" type="tns:ArrayOfString" />
<s:element minOccurs="1" maxOccurs="1" name="Message" type="tns:ArrayOfString" />
@amirkarimi
amirkarimi / dist-play-app-initd
Last active August 29, 2015 14:26 — forked from RadoBuransky/dist-play-app-initd
Init.d shell script for Play framework distributed application. Provides start, stop, restart and status commands to control applications packaged using standard "play dist" packaging command.
#!/bin/bash
#
# =========================================================================
# Copyright 2014 Rado Buransky, Dominion Marine Media
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@amirkarimi
amirkarimi / CookieAuthenticator.scala
Last active October 3, 2016 15:29
CookieAuthenticator implemented on top of ReactiveMongo and Silhouette
package services
import scala.concurrent.Future
import scala.concurrent.ExecutionContext
import com.mohiva.play.silhouette.api.StorableAuthenticator
import com.mohiva.play.silhouette.impl.daos.AuthenticatorDAO
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import com.mohiva.play.silhouette.api.LoginInfo
import reactivemongo.bson._
import reactivemongo.api.collections.default.BSONCollection
@amirkarimi
amirkarimi / 01.scala
Last active May 17, 2017 14:43
01-apply-settings-using-sbt-triggered-plugin
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0-SNAPSHOT"
)
lazy val core = (project in file("core"))
.settings(
commonSettings,
// other settings
)
@amirkarimi
amirkarimi / sort-import-group.el
Last active August 7, 2017 09:28
My Emacs Lisp Scripts
(defun sort-import-group ()
"This function basically sorts a comma separated list of strings but it's been
written to sort grouped imports in Scala.
Example:
`import org.temp.{ B, C, A }`
By selecting the grouped imported items (`B, C, A`) from the above code sample and run (M-x) `sort-group`
you'll get the following result:
`import org.temp.{ A, B, C }`"
(interactive)
(let* ((bounds (cons (region-beginning) (region-end)))
@amirkarimi
amirkarimi / linux_init.el
Last active September 9, 2017 20:45
My Emacs Config
;; global variables
(setq
inhibit-startup-screen t
create-lockfiles nil
make-backup-files nil
column-number-mode t
scroll-error-top-bottom t
show-paren-delay 0.5
use-package-always-ensure t
sentence-end-double-space nil
@amirkarimi
amirkarimi / blog_practical_cats_01.scala
Last active January 3, 2018 21:47
Don’t listen to them, learn Cats this way
def getUser(id: Int): Option[User] = ???
getUser(10) match {
case None => println(“User not found”)
case Some(user) => println(s”User: $user”)
}
def getUser(id: Int): Future[Option[User]] = ???
getUser(10).map {
case None => println(“User not found”)
case Some(user) => println(s”User: $user”)
}
def getUser(id: Int): Future[Option[User]] = ???
def getCity(user: User): Future[Option[City]] = ???
def getCountry(city: City): Future[Option[Country]] = ???
def getCountryByUserId(id: Int): Future[Option[Country]] = {
getUser(id) flatMap {
case None => Future.successful(None)
case Some(user) =>
getCity(user) flatMap {
case None => Future.successful(None)
def getCountryByUserId(id: Int): Future[Option[Country]] = {
val result = for {
user <- OptionT(getUser(id))
city <- OptionT(getCity(user))
country <- OptionT(getCountry(city))
} yield {
country
}
result.value
}