Skip to content

Instantly share code, notes, and snippets.

final Collection<Integer> ids =
Collections2.filter(Lists.transform(Arrays.asList(
input.split(",")),
new Function<String, Integer>() {
@Override
public Integer apply(@Nullable final String s) {
return s != null ? Ints.tryParse(s) : null;
}
}), new Predicate<Integer>() {
@Override
@mpolden
mpolden / gist:8300436
Created January 7, 2014 14:54
Ansible role-specific vars_prompt
- hosts: production
sudo: yes
roles:
- ntp
- postgresql
- nginx
- role: deploy
tags: deploy
vars_prompt:
- name: "version"
@mpolden
mpolden / gist:8418716
Last active January 3, 2016 05:49
Reproducible development environments using Vagrant

Reproducible development environments using Vagrant

Meta: Originally published by me on the internal Statoil developer blog. (2013-11-12)

The complexity of any given development environment often grows at the same rate as the project itself.

A large project can have countless dependencies such as a web server, a database, a caching system, a queue and more. This amounts to a lot of configuration and administration overhead. Suddenly, adding a new developer to the project means spending days just installing build tools, services, libraries and other dependencies before he/she can write any code.

Each developer might also be running different operating systems and using different tools, some might run Windows, others Linux or OS X. This adds to the complexity as some dependencies might have subtle platform-specific differences and/or bugs. Developing on an OS that differs from the production OS can also lead to subtle bugs when the application is deploye

@mpolden
mpolden / gist:8559017
Created January 22, 2014 13:49
Example for Ansible git-module and ssh agent forwarding
# files/env:
Defaults env_keep += "SSH_AUTH_SOCK"
# tasks/main.yml
- name: ensure sudo keeps SSH_AUTH_SOCK in environment
copy: src=env
dest=/etc/sudoers.d/env
mode=0440
owner=root
group=root
---
- hosts: all
sudo: yes
roles:
- role: postgresql
tags: postgresql
@mpolden
mpolden / gist:9305417
Created March 2, 2014 11:46
Activate command mode in atom with jj
# Install vim-mode
apm install vim-mode
# Open keymap (cmd-shift-p "keymap") and add
'.vim-mode.insert-mode:not(.mini)':
'j j': 'vim-mode:activate-command-mode'
$ vagrant status
/Applications/Vagrant/embedded/lib/ruby/2.0.0/rubygems/version.rb:191:in `initialize': Malformed version number string virtualbox (ArgumentError)
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/box_collection.rb:273:in `new'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/box_collection.rb:273:in `block (2 levels) in find'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/box_collection.rb:270:in `map'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/box_collection.rb:270:in `block in find'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/box_collection.rb:416:in `block in with_collection_lock'
from /Applications/Vagrant/embedded/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
from /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.0/lib/vagrant/box_collection.rb:415:in `with_collection_lock'
from /Applications
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from celery import Celery
from celery.schedules import crontab
app = Celery()
app.conf.CELERY_TIMEZONE = 'Europe/Oslo'
app.conf.CELERYBEAT_SCHEDULE = {
'every-minute': {t
def filter_iterable(key, iterable):
filtered = {}
for v in iterable:
if v[key] not in filtered:
filtered[v[key]] = v
return filtered.values()
;; result from clojure.xml/parse
{:tag :foo,
:attrs nil,
:content
[{:tag :bar,
:attrs
{:text "some text"
:more-text "some more text"},
:content nil}]}