Skip to content

Instantly share code, notes, and snippets.

module API
module ServiceCall
protected
def service_call(&block)
begin
puts "in begin block"
raise "exception occurred here"
parse_response(yield) if block_given?
@techwhizbang
techwhizbang / rspec2_mongoid_activerecord_rails3.rb
Created October 19, 2010 22:34
RSpec 2 with ActiveRecord and Mongoid together (temporary hack)
#put this in your spec_helper.rb if you're using Rails 3, Rspec2, Mongoid, and #ActiveRecord together until the "real" fix comes along
class RSpec::Core::Configuration
attr_accessor :fixture_path, :use_transactional_fixtures
def fixture_path=(path)
@fixture_path = path
end
def use_transactional_fixtures=(bool)
@use_transactional_fixtures = bool
override def calculate(cartItem: CartItem): DiscountResult = {
val saleDao = saleDao.findSale
if (shopKeeperSale != None) {
if (isThis(cartItem.getProductData) ||
isThat(cartItem.getProductData)) {
new DiscountResult(DiscountType.SOME_TYPE_A, percentageOff)
} else {
new DiscountResult(DiscountType.SOME_TYPE_B, percentageOff)
@techwhizbang
techwhizbang / injectable.rb
Created July 21, 2011 06:38
Ruby inject method implementation
require 'rubygems'
require 'rspec'
module Enumerable
def inject(*args, &block)
if(args.size == 2)
inject_binary_operation(args[0], args[1], self)
elsif(args.size == 1 && !block_given?)
inject_binary_operation(self.first, args[0], self.drop(1))
else
@techwhizbang
techwhizbang / selenium-grid.sh
Created October 28, 2011 17:34
Selenium Grid service script
#!/bin/bash
case "${1:-''}" in
'start')
if test -f /tmp/selenium-grid.pid
then
echo "Selenium Grid is already running."
else
java -jar /home/bkr/selenium/selenium-server-standalone-2.9.0.jar -port 5555 -role hub > /var/log/selenium/selenium-grid.log 2> /var/log/selenium/selenium-grid-error.log & echo $! > /tmp/selenium-grid.pid
echo "Starting Selenium Grid..."
@techwhizbang
techwhizbang / selenium-grid.sh
Created October 28, 2011 17:34
Selenium Grid service script
#!/bin/bash
case "${1:-''}" in
'start')
if test -f /tmp/selenium-grid.pid
then
echo "Selenium Grid is already running."
else
java -jar /home/bkr/selenium/selenium-server-standalone-2.9.0.jar -port 5555 -role hub > /var/log/selenium/selenium-grid.log 2> /var/log/selenium/selenium-grid-error.log & echo $! > /tmp/selenium-grid.pid
echo "Starting Selenium Grid..."
@techwhizbang
techwhizbang / prepare.clj
Created January 18, 2012 21:33
Super long running Clojure shell commands
(ns my-app.db.prepare
(:use [clojure.java.shell :only [sh]]))
(defn -main []
"Will create the database if it does not exist yet for the specified environment"
(let [db-name "my_db"
db-user "root"
db-pass ""]
@techwhizbang
techwhizbang / gist:2008998
Created March 9, 2012 22:14
lobos alter :modify not working
(defmigration alter-ip-address-column-for-ipv6-20120125
(up []
(alter :modify
(table :notifications
(column :ip_address (data-type :varchar 45) :not-null))))
(down []
(alter :modify
(table :notifications
(column :ip_address (data-type :varchar 15))))))
@techwhizbang
techwhizbang / env_var_lein_project.clj
Created February 8, 2014 18:30
Difficulty reading environment variables in Leiningen project.clj
; consider this example
(let [_ (prn (System/getenv))]
(defproject your-clojure-app "1.0.0-SNAPSHOT"
:mirrors {#".+" {:url "https://internal.artifactory.repo.com/repo"
:username :env/artifactory_username
:password :env/artifactory_password}}))
; in the above example I confirm that the environment variables that I want
@techwhizbang
techwhizbang / noctor_authentication
Created June 18, 2014 21:16
java.lang.IllegalArgumentException: No matching ctor found for class org.sonatype.aether.repository.Authentication
java.lang.IllegalArgumentException: No matching ctor found for class org.sonatype.aether.repository.Authentication
at clojure.lang.Reflector.invokeConstructor(Reflector.java:183)
at cemerick.pomegranate.aether$set_authentication.invoke(aether.clj:159)
at cemerick.pomegranate.aether$make_repository.invoke(aether.clj:179)
at cemerick.pomegranate.aether$mirror_selector$reify__141.getMirror(aether.clj:479)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:93)