Skip to content

Instantly share code, notes, and snippets.

@ilguzin
ilguzin / gen-self-signed.txt
Created November 26, 2013 06:01
Create self-signed certificate
# Create key:
openssl genrsa -out DOMAINCOM.com.key 2048
# And the certificate:
openssl req -new -x509 -key DOMAINCOM.key -out DOMAINCOM.cert -days 3650 -subj /CN=DOMAIN.COM
#!/usr/bin/env bash
C="0" # count
while [ $C -lt 20 ]
do
case "$(($C % 4))" in
0) char="/"
;;
1) char="-"
;;
@ilguzin
ilguzin / progress.sh
Last active December 28, 2015 18:49
Progress bar (dots...) on operations execution
#
# Utilities
#
dot_progress() {
while true
do
echo -n "."
sleep 2
done
}
@ilguzin
ilguzin / Boot.scala
Created November 12, 2013 06:39
Turn on ssl support in spray
import spray.routing._
import spray.routing.directives.LogEntry
import spray.http.HttpRequest
import spray.httpx.encoding.{Gzip, NoEncoding}
import akka.event.Logging._
/** Main class to start up the application */
object Boot extends App with SimpleRoutingApp {
#
# Slightly tighter CORS config for nginx
#
# A modification of https://gist.github.com/1064640/ to include a white-list of URLs
#
# Despite the W3C guidance suggesting that a list of origins can be passed as part of
# Access-Control-Allow-Origin headers, several browsers (well, at least Firefox)
# don't seem to play nicely with this.
#
@ilguzin
ilguzin / socket_idle_timeout.java
Created June 5, 2013 08:44
The way to organize read timeout (read idle timeout) for socket connection with Netty. See. http://docs.jboss.org/netty/3.2/api/org/jboss/netty/handler/timeout/ReadTimeoutHandler.html
public class MyPipelineFactory implements ChannelPipelineFactory {
private final Timer timer;
private final ChannelHandler timeoutHandler;
public MyPipelineFactory(Timer timer) {
this.timer = timer;
this.timeoutHandler = new ReadTimeoutHandler(timer, 30), // timer must be shared.
}
@ilguzin
ilguzin / akka_custom_ser_config
Created April 25, 2013 20:46
Akka config for remoting + serialization cutomization
akka {
actor {
provider = "akka.remote.RemoteActorRefProvider"
serialize-messages = on
serializers {
proto = "akka.remote.serialization.ProtobufSerializer"
}
serialization-bindings {
"scala.collection.immutable.List" = proto
@ilguzin
ilguzin / implicits_create_and_import.scala
Created April 12, 2013 07:12
Useful way of injecting implicits in the scope. We add here a companion object with implicits for mongo database requests. Then make the object nested in the desired class by importing.
object UserDaoImpl {
object Implicits {
implicit object AccountWriter extends BSONDocumentWriter[Account] {
def write(acc: Account) = BSONDocument(
"email" -> acc.email)
}
implicit object AccountReader extends BSONDocumentReader[Account] {
@ilguzin
ilguzin / mongo_unique_index_on_embedded_document
Last active December 16, 2015 02:59
As comes from official mongo documentation you cannot create unique index on fields from embedded documents. Here is a workaround for those using $push to append values to array of embedded documents.
Mongo shell command
> db.users.update(
{ community:'Coomunity1',
'users.login': {'$ne': 'Login1'}
},
{ $push:
{ users: {login:'Login1', pwd:'*****'} }
},
{upsert: true})
Here are a few alternatives you might wish to consider:
1. Use a view bound
If it's possible to change the function that takes a List of Bs, this would be the simplest solution. Modify it to accept a List of things that can be converted to Bs. That is,
def myfun(l: List[B]) = ...
would become
def myfun[X <% B](l: List[X]) = ...