Skip to content

Instantly share code, notes, and snippets.

@nlinker
nlinker / gist:3878956
Created October 12, 2012 12:23
Scala feature list

Basic features absent in Java

  • First-class functions
  • Implicit parameters / conversions
  • Pattern matching, case classes
  • Type inference
  • Higher-kinded types (abstraction over type constructors)
  • Monadic for comprehensions
  • Variance annotations
  • Interfaces with behavior (traits)
@nlinker
nlinker / gist:3931271
Created October 22, 2012 12:19
Find the thread by name and change its priority
// ...
val connection = factory.newConnection()
changeInnerPriority(connection,
config.get[Int]("tq.connectionPriority").getOrElse(Thread.NORM_PRIORITY))
// ...
def changeInnerPriority(connection: com.rabbitmq.client.Connection,
priority: Int): Unit = {
def getHostAddressAsString: String = {
connection.getAddress.getHostAddress
@nlinker
nlinker / amo_rabbit_prod_report.php
Created October 31, 2012 15:54 — forked from oremj/amo_rabbit_prod_report.php
Rabbit ganglia metrics
<?php
/* Pass in by reference! */
function graph_amo_rabbit_prod_report ( &$rrdtool_graph ) {
global $context,
$hostname,
$mem_shared_color,
$mem_cached_color,
$mem_buffered_color,
@nlinker
nlinker / gist:4057857
Created November 12, 2012 06:47 — forked from invalidusrname/Vagrantfile
Connecting between VMs with vagrant
config.vm.define :puppet do |app_config|
app_config.vm.customize ["modifyvm", :id, "--name", "puppet", "--memory", "512"]
app_config.vm.box = "precise_with_puppet"
app_config.hosts.name = 'puppet'
app_config.vm.host_name = 'puppet'
app_config.vm.forward_port 22, 2222, :auto => true
app_config.vm.forward_port 80, 4561
app_config.vm.network :hostonly, "33.13.13.01"
app_config.vm.provision :shell do |shell|
shell.path = "../puppet_master_setup.sh"
@nlinker
nlinker / gist:4243761
Created December 9, 2012 07:25
Scala cake pattern
abstract class Cake {
def top: String
def middle: String
def bottom: String
override def toString = top
}
trait Cherry { this: Cake =>
def top = "cherry on top of " + middle
}
@nlinker
nlinker / C:\Vbox\rabbits-headless.ps1
Created December 10, 2012 07:29
Powershell script to run several vagrant machines headless
# make sure this mode is enabled under administrator: Set-ExecutionPolicy RemoteSigned
# use a batch file like this:
# C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe C:\Vbox\rabbits-headless.ps1
$items = @( 'vagrant-rabbitmq-cluster_1351840619', 'vagrant-rabbitmq-cluster_1351840685', 'vagrant-rabbitmq-cluster_1351840745', 'vagrant-rabbitmq-cluster_1351840804' )
Foreach ($item in $items) {
$p = '-s ' + $item
start-process 'C:\ProgramsX\Oracle\VirtualBox\VBoxHeadless.exe' $p -WindowStyle Hidden
@nlinker
nlinker / gist:4662307
Created January 29, 2013 06:40
How to use scalaz.Validation?
//From what I can tell the main things to tools to use are map, fold and lift.
//When you want to get something out of a validation regardless of
//whether it is a success or a failure
//(analogous to option's 'getOrElse') use fold:
class Example {
val s = 1.success[String]
// s: scalaz.Validation[String,Int] = Success(1)
@nlinker
nlinker / AA.md
Created February 4, 2013 00:28 — forked from sadache/AA.md

Is socket.push(bytes) all you need to program Realtime Web apps?

One of the goals of Play2 architecture is to provide a programming model for what is called Realtime Web Applications.

Realtime Web Applications

Realtime Web Applications are applications that make use of Websockets, Server Sent Events, Comet or other protocols offering/simulating an open socket between the browser and the server for continuous communication. Basically, these applications let users work with information as it is published - without having to periodically ping the service.

There are quite a few web frameworks that target the development of this type of application: but usually the solution is to simply provide an API that allows developers to push/receive messages from/to an open channel, something like:

using Umbraco.Core;
using Umbraco.Core.Services;
using Umbraco.Web.Mvc;
using Umbraco.Web.Routing;
namespace Our.Umbraco
{
public class MyApplication : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
package org.apache.hadoop.examples;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;