Skip to content

Instantly share code, notes, and snippets.

@cacoco
cacoco / precompiler.rb
Last active September 25, 2015 12:28
Buildr Extension for precompiling JSP files.
module Precompiler
include Extension
first_time do
# Define task not specific to any projet.
desc 'Precompile jsps'
Project.local_task('precompile' => 'compile') { |name| "Precompiling #{name}" }
end
before_define do |project|
@cacoco
cacoco / buildr_apt_task.rb
Created July 18, 2012 17:13
Apache Buildr Task for Generating Java sources using the Java Annotation Processor
AWS_JAVA_SDK_BUILD_TOOLS = ["com.amazonaws:aws-java-sdk:jar:1.3.10",
"com.amazonaws:aws-java-sdk-flow-build-tools:jar:1.3.10"]
# The following is assumed to be embedded inside a project definition, otherwise
# you will need to pass the project to the task.
...
# Task for Generating Sources via Java APT, note this overwrites any current source
task :apt do
rm_rf project.path_to(:src, :generated, :java)
@cacoco
cacoco / tmux.conf
Created November 7, 2012 18:44
Tmux sensible defaults
set-option -g prefix C-a
bind-key C-a last-window
# Get scrolling in pane to work
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
# Set up horizontal and vertical splitting
unbind %
bind \ split-window -h
bind - split-window -v
@cacoco
cacoco / gist:4757252
Created February 11, 2013 20:18
Accumulator Generator in Scala: http://www.paulgraham.com/accgen.html
def foo(n: Int) = (i: Int) => n + i
@cacoco
cacoco / maxmind.rb
Last active December 17, 2015 00:00
Thor script to download lastest MaxMind (http://www.maxmind.com/en/home) database and install it into a Maven compatible repository via the passed in repository URL and repository ID.
# Usage:
# thor maxmind --version=VERSION --repositoryUrl=URL --repositoryId=ID [--temp=/tmp]
class Maxmind < Thor
include Thor::Actions
class_options :version => :string,
:repositoryUrl => :string,
:repositoryId => :string,
:temp => File.join(ENV["HOME"], "Downloads")
@cacoco
cacoco / maxmind_pom.xml
Last active December 17, 2015 00:00
pom.xml snippet for including the created maxmind JAR file as a project dependency.
<properties>
<geocity.version>2011-10-25</geocity.version>
</properties>
...
<dependency>
<groupId>com.maxmind</groupId>
<artifactId>geocity</artifactId>
<version>${geocity.version}</version>
public class MyLookupServiceImpl implements ApplicationContextAware {
private com.maxmind.geoip.LookupService lookupService;
private String dataPath; // classpath location of .dat file, e.g GeoIPCity.dat
private ApplicationContext context;
// constructor that allows us to inject a LookupService, e.g. for testing
public MyLookupServiceImpl(com.maxmind.geoip.LookupService lookupService) {
this.lookupService = lookupService;
}
(ns fizzbuzz.core)
(defn multiple? [x n]
(= 0 (mod x n)))
(defn fizzbuzz [number]
(if (multiple? number 3)
(if (multiple? number 5) (prn "FizzBuzz") (prn "Fizz"))
(if (multiple? number 5) (prn "Buzz") (prn number))))
function boot-tmux {
echo -ne "\033]0;$@\007"
tmux new-session -d -s $@
tmux send-keys -t $@ "teamocil --here $@" C-m
tmux attach-session -t $@
}
[Tue May 12 11:33:31 ccoco@horus finatra-hello-world (master)]$ ../../sbt clean test
downloading sbt-launch.jar from http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/0.13.8/sbt-launch.jar
[info] Loading project definition from /Users/ccoco/github/twitter/finatra/examples/finatra-hello-world/project
[info] Updating {file:/Users/ccoco/github/twitter/finatra/examples/finatra-hello-world/project/}finatra-hello-world-build...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to finatraHelloWorld (in build file:/Users/ccoco/github/twitter/finatra/examples/finatra-hello-world/)
[success] Total time: 0 s, completed May 12, 2015 11:34:00 AM
[info] Updating {file:/Users/ccoco/github/twitter/finatra/examples/finatra-hello-world/}finatraHelloWorld...
[info] Resolving jline#jline;2.12.1 ...