Skip to content

Instantly share code, notes, and snippets.

Avatar

Lenny Marks lenny

  • American Physical Society
  • Long Island, NY
View GitHub Profile
View tmux.conf
# 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 Jan 18, 2017
Snippet showing clojure.spec instrumentation with stubbing through deftest
View test.clj
(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 Dec 2, 2016
Modified version of James' script that bombs out with error when bug is detected
View safari.js
/* 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
View background_job_watcher.rb
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 Aug 29, 2015
Script used while upgrading from Rails 2 to Rails 3/4
View fix_amp_eq.rb
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
BDD example
View A.rb
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
View gist:1700352
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 Jan 9, 2012
Java Classpath Helper
View java_classpath.rb
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 Jan 4, 2012
Custom Log4j appender to log messages into database via Hibernate
View HibernateAppender.java
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 Dec 21, 2011
ruby block interface for anonymous class
View TxCallback.java
public interface TxCallback {
public Object execute(TransactionHolder txHolder) throws Exception;
}