Skip to content

Instantly share code, notes, and snippets.

View jeroenr's full-sized avatar

Jeroen Rosenberg jeroenr

View GitHub Profile
val src = Source.actorRef[ByteString](1000, OverflowStrategy.dropHead)
FlowGraph.closed(src) { implicit builder =>
byteStringSource =>
import FlowGraph.Implicits._
// for junctions / fan-in / fan-out shapes we need to builder.add explicitly
val broadcaster = builder.add(Broadcast[String](2))
// for Flows builder.add is implicit, if I'm not mistaking
val src = Source.actorRef[ByteString](1000, OverflowStrategy.dropHead)
FlowGraph.closed(src) { implicit builder =>
byteStringSource =>
import FlowGraph.Implicits._
// for junctions / fan-in / fan-out shapes we need to builder.add explicitly
// val broadcaster = builder.add(Broadcast[String](2))
val broadcaster: UniformFanOutShape[String,String] = Broadcast[String](2) // builder.add is done implicitly
def ~>[Out](junction: UniformFanInShape[T, Out])(implicit b: Builder[_]): PortOps[Out, Unit] = {
def bind(n: Int): Unit = {
if (n == junction.inSeq.length)
throw new IllegalArgumentException(s"no more inlets free on $junction")
else if (b.module.upstreams.contains(junction.in(n))) bind(n + 1) // it's already part of the graph
else b.addEdge(importAndGetPort(b), junction.in(n)) // b.add(), add it to the graph
}
bind(0)
junction.out
}
@jeroenr
jeroenr / NgramExtractor.scala
Last active August 29, 2015 14:28
NGram extraction using Stackable traits in Scala
object Boot extends App {
val extractor = new SentenceAnalyzer
with NGramExtraction
with Unigrams
with Bigrams
with Trigrams
val sentences = Source.fromInputStream(getClass.getResourceAsStream("/input.txt")).getLines().toIterable
println(extractor.analyze(sentences))
}
@jeroenr
jeroenr / Vagrantfile
Created March 15, 2012 15:33
Vagrant configuration for Puppet provisioning
### Config for Vagrant using Puppet provisioning. Requires 0.9.5 or higher ###
# Configuration
hostname = "elmar-test-jero"
puppet_manifests = "~/Projects/Puppet/manifests/"
puppet_modules = "~/Projects/Puppet/modules/"
## ================================
# Don't edit below unless you know what you're doing
## ================================
@jeroenr
jeroenr / example.pp
Created March 16, 2012 09:06
Using puppet templates example
## Use template from module 'elmar'
class repo-nonfree {
file { "/etc/apt/sources.list.d/non-free.list":
ensure => present,
content => $operatingsystem ? {
"ubuntu" => template("elmar/apt/sources.list.d/ubuntu-partner.list.erb"),
"debian" => template("elmar/apt/sources.list.d/non-free.list.erb"),
default => template("elmar/apt/sources.list.d/non-free.list.erb"),
},
@jeroenr
jeroenr / example.pp
Created March 16, 2012 09:24
Using puppet filebucket example
file { "/etc/apt/trusted.gpg.d/mozilla.gpg":
ensure => present,
source => $operatingsystem ? {
"ubuntu" => "puppet:///elmar/apt/trusted.gpg.d/mozilla_ubuntu.gpg",
"debian" => "puppet:///elmar/apt/trusted.gpg.d/mozilla_debian.gpg",
},
notify => Exec["aptgetupdate"],
}
@jeroenr
jeroenr / deploy.rb
Created April 5, 2012 14:02
Capistrano deploy:setup task without root permission
namespace :deploy do
task :setup, :except => { :no_release => true } do
dirs = [deploy_to, releases_path, shared_path]
dirs += shared_children.map { |d| File.join(shared_path, d.split('/').last) }
run "mkdir -p #{dirs.join(' ')}"
run "chmod g+w #{dirs.join(' ')}" if fetch(:group_writable, true)
end
end
@jeroenr
jeroenr / Vagrantfile.rb
Created April 13, 2012 06:56
Multi VM setup with Vagrant
### Elmar configuration file for Vagrant. Requires 0.9.5 or higher ###
## ================================
# Don't edit below unless you know what you're doing
## ================================
Vagrant::Config.run do |config|
config.vm.define :frontend do |frontend_config|
## Provisioning
frontend_config.vm.provision :puppet do |puppet|
puppet.module_path = "modules"
@jeroenr
jeroenr / import.rb
Created May 1, 2012 14:42
Replace box name with uuid before passing ovf to VirtualBox to enable parallellization
require 'uuid'
module Vagrant
module Action
module VM
class Import
def initialize(app, env)
@app = app
end