Skip to content

Instantly share code, notes, and snippets.

View lenny's full-sized avatar

Lenny Marks lenny

  • American Physical Society
  • Long Island, NY
  • 10:33 (UTC -04:00)
View GitHub Profile
# switch C-b -> C-a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# quick pane cycling
unbind ^A
bind ^A select-pane -t :.+
# mouse support
@lenny
lenny / gist:1278231
Created October 11, 2011 14:30
script/tomcat-console to run Rails console from a WAR
#!/usr/bin/env jruby
raise "Must specify CATALINA_HOME" unless ENV['CATALINA_HOME']
ENV['GEM_HOME'] ||= File.expand_path('../../gems', __FILE__)
require File.expand_path('../../../META-INF/init', __FILE__)
# expected by rails/commands
APP_PATH = File.expand_path('../../config/application', __FILE__)
@lenny
lenny / test.clj
Last active January 18, 2017 22:00
Snippet showing clojure.spec instrumentation with stubbing through deftest
(defn assert-valid [spec-check]
(let [failure (-> spec-check first :failure)]
(is (nil? failure))))
(deftest manifest
(let [find-spec (s/fspec :args (s/cat :id ::submission-directory/id)
:ret (s/or :found ::submission-directory/submission-directory :not-found nil?))]
(stest/instrument ['submissions-svr.db.submission-directories/find `submission/manifest-files]
{:spec {'submissions-svr.db.submission-directories/find find-spec}
@lenny
lenny / safari.js
Created December 2, 2016 14:39
Modified version of James' script that bombs out with error when bug is detected
/* selenium webdriver safari 10 OSX Sierra testing
[Error] Failed to load resource: The network connection was lost.
Note: Script is unable to capture console log errors. Error occurs
when page is blank
Error occurs for the following urls
https://authors.aps.org/Submissions
https://authors.staging.aps.org/Submissions
==========================================================================================
Running script:
Install node js v7.2.0
@lenny
lenny / A.rb
Created May 29, 2012 17:04
BDD example
describe ResubmissionsController do
...
# Probably not the most ideal start-off point
# since it is fairly rare un-RESTFul action, but....
describe '#mark_as_processed' do
it 'responds with 404:not_found when no matching resubmissions were found' do
Resubmission.should_receive(:mark_as_processed).with('aa1001').and_return(0)
do_get('aa1001')
response.status.should == 404
end
@lenny
lenny / gist:1700352
Created January 29, 2012 19:51
macros approach to requestable examples as expressed in http://mutuallyhuman.com/blog/2012/01/27/rspec-requestable-examples
module WordListMacros
def it_strips_double_quotes
it "strips double quotes" do
subject.list_of_words = %w("foo" "bar")
subject.list_of_words.should eq(%w(foo bar))
end
end
def it_strips_single_quotes
it "strips single quotes" do
@lenny
lenny / java_classpath.rb
Created January 9, 2012 15:51
Java Classpath Helper
class JavaClasspath
class << self
def bootstrap(jar_dirs, classpath_dirs)
jar_dirs.each do |jardir|
Dir.entries(jardir).grep(/\.jar$/) {|jar| add_expanded_path(File.join(jardir, jar))}
end
classpath_dirs.each do |cp_dir|
add_expanded_path(cp_dir)
@lenny
lenny / HibernateAppender.java
Created January 4, 2012 17:50
Custom Log4j appender to log messages into database via Hibernate
package org.aps.webprowo.hibernate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Appender;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
import org.aps.eop.dao.DataAccessUtils;
@lenny
lenny / TxCallback.java
Created December 21, 2011 19:22
ruby block interface for anonymous class
public interface TxCallback {
public Object execute(TransactionHolder txHolder) throws Exception;
}
@lenny
lenny / java_properties.rb
Created October 24, 2011 14:54
Ruby wrapper around Java Properties
# More rubyish/convenient interface to Java Properties(e.g. Loading connection config from properties file)
class JavaProperties
def initialize(name)
input_stream =
Java::Java.lang.Thread.currentThread.contextClassLoader.getResourceAsStream(name)
if input_stream
@properties = Java::java.util.Properties.new
@properties.load(input_stream)
input_stream.close