Skip to content

Instantly share code, notes, and snippets.

@yarinb
yarinb / database.yml.erb
Created May 2, 2012 09:35
Elegant (??) solution to database.yml passwords
# Since you already have ssh keypair on your deployment host, you may use it to decrypt
# database credentials at load time.
#
# The solution can be tweaked a bit to decrypt with capistrano at deployment time.
# In case where the private key is passphrase protected this won't work but it's pretty straight forward to fix it.
#
# Hope it's a nice starting point for a more mature solution.
#
# --Yarin
@yarinb
yarinb / gist:2727648
Created May 18, 2012 21:18
Rspec stubs are bad practice
require 'rspec/mocks/standalone'
class Service
def self.access_thirdparty_action
puts "communicating with the world!"
end
end
class ServiceManager
@yarinb
yarinb / ServerFactory.java
Created June 1, 2012 08:11
add SessionManager to Dropwizard's Jetty
private Handler createExternalServlet(ImmutableMap<String, ServletHolder> servlets,
ImmutableMultimap<String, FilterHolder> filters,
ImmutableSet<EventListener> listeners) {
// set ServletContextHandler.SESSIONS option
final ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
// set a default SessionHandler
handler.setSessionHandler(new SessionHandler());
handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
handler.setBaseResource(Resource.newClassPathResource("."));
@yarinb
yarinb / SecretResource.java
Created June 22, 2012 18:49
Simple authentication for jax-rs resources
@Path("/secret")
public class SecretResource {
@GET
@Path("/secured")
public String showSecret(@Auth User user) {
return "Hello " + user.getUsername() + ". This is secret!";
}
@yarinb
yarinb / .osx.sh
Created July 29, 2012 12:04
OSX For Hackers - ML edition
# ~/.osx — http://mths.be/osx
###############################################################################
# General UI/UX #
###############################################################################
# Set computer name (as done via System Preferences → Sharing)
scutil --set ComputerName "MathBook Pro"
scutil --set HostName "MathBook Pro"
scutil --set LocalHostName "MathBook-Pro"
@yarinb
yarinb / solve.rb
Created October 27, 2012 21:24
scrabble solve
#!/usr/bin/env ruby
dict = File.open('/usr/share/dict/words', 'r').read
letters = ARGV[0] unless ARGV.empty?
def can_make?(word, letters)
return letters.include? word if word.size == 1
letters.include? word[0] and
can_make?(word[1..-1], letters.sub(/#{word[0]}/, ""))
end
@yarinb
yarinb / config
Created December 21, 2012 20:19
Reuse SSH sessions
# put this in ~/.ssh/config
Host *
Compression yes
CompressionLevel 7
Cipher blowfish
ServerAliveInterval 600
ControlMaster auto
ControlPath /tmp/ssh-%r@%h:%p
# OSX for Hackers (Mavericks/Yosemite)
#
# Source: https://gist.github.com/brandonb927/3195465
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Ask for the administrator password upfront

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, etc)
  • CI runs only the tests that matter (future)
package my.elasticsearch;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;