Skip to content

Instantly share code, notes, and snippets.

Soheil Hassas Yeganeh soheilhy

Block or report user

Report or block soheilhy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
soheilhy / HttpServer.scala
Created Jun 14, 2012
Routing based on HTTP method in Finagle
View HttpServer.scala
import com.twitter.finagle.http.path._
import com.twitter.finagle.http.service.RoutingService
import com.twitter.finagle.http.{Request, Response, RichHttp, Http}
import com.twitter.finagle.{Service, SimpleFilter}
import org.jboss.netty.handler.codec.http._
import org.jboss.netty.handler.codec.http.HttpResponseStatus._
import org.jboss.netty.handler.codec.http.HttpVersion.HTTP_1_1
import org.jboss.netty.buffer.ChannelBuffers.copiedBuffer
import org.jboss.netty.util.CharsetUtil.UTF_8
import com.twitter.util.Future
soheilhy / CakePatternIm.scala
Created Jun 20, 2012
Cake Pattern Imitated
View CakePatternIm.scala
// You create the trait.
trait JavaScriptCompilerComponent {
def compiler: JavaScriptCompiler
trait JavaScriptCompiler {
def compile(files: Seq[Source]): String
// You implement it.
View CakePattern.scala
// You create the trait.
trait JavaScriptCompilerComponent {
def compiler: JavaScriptCompiler
// You add the abstract method to get all javascript files.
def jsFiles: Seq[Source]
def getCompiledJavaScript = compiler.compile(jsFiles)
trait JavaScriptCompiler {
soheilhy / gist:3077008
Created Jul 9, 2012
A generic routing service
View gist:3077008
class RoutingService[REQUEST <: Request, RESPONSE](
val routes: PartialFunction[Request, Service[REQUEST, RESPONSE]])
extends Service[REQUEST, RESPONSE] {
protected[this] val requestToService = routes
def apply(request: REQUEST): Future[RESPONSE] = {
val service = requestToService(request)
View dummyserver.js
var http = require('http');
var hello = function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Hello! <br />');
res.write('<br />' +
'URL:' + req.url + '<br />' +
'Method:' + req.method + '<br />');
soheilhy /
Last active Oct 19, 2019
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for,, and on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers


MongoDB + NodeJS Tutorial


  • You have node.js and npm installed on your machine.
  • If you use CDF:
    • Use bash or zsh as your shell.
    • Make sure npm installs packages locally as you don't have root permissions. To do so, you can edit ~/.npmrc and add the following line:
      • prefix=$NODE_HOME
    • $NODE_HOME is the directory in which you have installed node.js.

Testing Node.JS applications using Mocha

Mocha is a unittest framework for Node. In this document, we explain how you can test your javascript code and also your HTTP servers.

Installing Mocha

Use npm to install Mocha:

npm install mocha
soheilhy / queue.go
Last active Aug 29, 2015
Basic structures in taskq
View queue.go
// Queue represents a named queue.
type Queue string
// Task represents a task in a queue.
type Task struct {
ID uint64 `json:"id"` // Task's globally unique ID assigned by taskq.
Queue Queue `json:"queue"` // Task's queue.
Body []byte `json:"body"` // Task's client data.
soheilhy / queue.go
Last active Aug 29, 2015
Messages in taskq
View queue.go
// Enqueue enqueus a task.
type Enque struct {
Task // The task to be enqueued.
// Deque represents a message emitted to dequeue a task from a queue.
type Deque struct {
Queue // The queue to dequeue a task from.
You can’t perform that action at this time.