Skip to content

Instantly share code, notes, and snippets.

View lenny's full-sized avatar

Lenny Marks lenny

  • American Physical Society
  • Long Island, NY
  • 15:58 (UTC -05: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 / 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
class BackgroundJobWatcher
attr_accessor :mailer, :error_io
class << self
def attempt(job_name, &blk)
new.attempt(job_name, &blk)
end
end
def initialize(opts = {})
@lenny
lenny / fix_amp_eq.rb
Last active August 29, 2015 13:57
Script used while upgrading from Rails 2 to Rails 3/4
dir = ARGV[0]
raise "Usage: #{$0} <DIR>" if dir.nil?
Dir[File.join(dir, '**/*.haml')].each do |f|
s = File.read(f)
lines = []
s.each_line do |l|
l = l.gsub('&=', '=')
@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;
}