Skip to content

Instantly share code, notes, and snippets.

View teaforthecat's full-sized avatar

Chris Thompson teaforthecat

View GitHub Profile
@teaforthecat
teaforthecat / comment-or-uncomment-sexp.el
Created October 18, 2015 18:10
one function with a few lines addded to keep the structure of lisp forms when commenting a form inside another form
(defun comment-sexp--raw ()
"Comment the sexp at point or ahead of point."
(pcase (or (bounds-of-thing-at-point 'sexp)
(save-excursion
(skip-chars-forward "\r\n[:blank:]")
(bounds-of-thing-at-point 'sexp)))
(`(,l . ,r)
(goto-char r)
(skip-chars-forward "\r\n[:blank:]")
(save-excursion

Keybase proof

I hereby claim:

  • I am teaforthecat on github.
  • I am teaforthecat (https://keybase.io/teaforthecat) on keybase.
  • I have a public key ASB1dfXKtsulaHTXHgRPQC4pzMzpu2CbqIJGJOEw2whMcwo

To claim this, I am signing this object:

@teaforthecat
teaforthecat / common.yaml
Created December 1, 2013 00:00
puppet-hiera hash data access fails why?
nfs_volumes:
home: "%{gdnet_env}-netapp1:/vol/home/qtree0"
yum_cache: "%{gdnet_env}-netapp1:/vol/yum_cache/qtree0"
techops: "%{gdnet_env}-netapp1:/vol/techops/qtree0"
websites: "%{gdnet_env}-netapp1:/vol/websites_%{gdnet_env}/qtree0"
apache_logs: "%{gdnet_env}-netapp1:/vol/apache_logs_%{gdnet_env}/qtree0"
evolution_logs: "%{gdnet_env}-netapp1:/vol/evolution_logs_%{gdnet_env}/qtree0"
@teaforthecat
teaforthecat / personal_consumer.clj
Last active December 26, 2015 14:19
Consume a kafka message stream of filtered keys
(def consumer-registry (atom {}))
(defn get-or-create-message-stream [topic]
(if-let [message-stream (get @consumer-registry topic)]
message-stream
(let [[cnsmr messages] (kafka/open-consumer "consumer-registry" topic)
new-message-stream (ms/->source messages)]
;; create lifespan for consumer of 1 minute, should probably be a component
(a/go (a/<! (a/timeout 60e3 ))
(kafka/shutdown cnsmr)
@teaforthecat
teaforthecat / jobs.clj
Created December 18, 2015 03:30
An onyx job builder, basically a shortcut to this: kafka-input->function->kafka-output
(ns bones.jobs
" given a symbol and config, build all components of an onyx job
with three tasks kafka-input->function->kafka-output
(def x.y/fn [s] (str s \"-yo\"))
(api/submit-jobs (bones.jobs/build-jobs {} [:x.y/fn]))
(kafka/produce \"x.y..fn-input\" \"hello\")
(kafka/consume \"x.y..fn-output\") => \"hello-yo\"
")
(defn topic-reader [^String topic]
@teaforthecat
teaforthecat / ruby.el
Created March 21, 2013 01:33 — forked from fujin/ruby.el
(setq ruby-deep-indent-paren nil)
(defadvice ruby-indent-line (after unindent-closing-paren activate)
(let ((column (current-column))
indent offset)
(save-excursion
(back-to-indentation)
(let ((state (syntax-ppss)))
(setq offset (- column (current-column)))
(when (and (eq (char-after) ?\))
(not (zerop (car state))))
@teaforthecat
teaforthecat / double_nested_fields.html.haml
Created February 13, 2013 16:35
This is an example of a field set using the nested_form gem along with the twitter bootstrap style framework. It enables very efficient editing of data and relationships since three objects can be edited at once. Instead of being directed to another form and having to go back, ajax is used to create a dynamic form.
%li.reference_group
.container-fluid
.row-fluid
.span1.move
%i.icon-move
.span4
= f.input_field :label_markdown, placeholder: '<markdown enabled>'
= f.input :order, as: :hidden
.span7
= f.link_to_remove class: 'btn btn-danger' do
# wraps third..+ paragraphs in div.more_content
# first two paragraphs are left in tack
def read_more_content html
first, second, *rest = Nokogiri::HTML::fragment(html).children
out = first.to_s + second.to_s
if rest.present?
out << "\n\n<div class=\"more_content\">"
out << rest.map(&:to_s).reduce(:+)
out << "</div>"
end
@teaforthecat
teaforthecat / catalog_entry.rb
Last active December 13, 2015 17:08
Custom html parser. This was used to convert html files which were exported from an older Adobe InDesign file into markdown. The html was inconsistent and varied but this handled 90 percent of the files. The remaining cases were edited by hand in a form with a markdown enabled text area.
# renders markdown with footnotes matching Pandoc's syntax,
# but renders html with custom formatting in the class methods link_to_text_replace, link_to_fn_replace
class CatalogEntry
LINK_TO_FN = "[^%d] "
LINK_TO_TEXT = "[^%d]: %s"
CITATION = "%{last}, %{first}%{other}. \"%{title}.\" In _Bits &amp; Pieces Put Together to Present a Semblance of a Whole: Walker Art Center Collections_, edited by Joan Rothfuss and Elizabeth Carpenter. Minneapolis, MN: Walker Art Center, 2005."
FILE_TEMPLATE = "B&Pcat-%{last},%{first}_2005"
FILE_NAME_REGEX = /B&Pcat-(.+),(.+)_2005.*/
@teaforthecat
teaforthecat / initializers_dragonfly.rb
Last active December 11, 2015 06:09
Store the processed image on the datastore before being served by dragonfly (pre-caching). The url needs to be accesses programatically, like in a background job.
# store the job before it has a chance to be served by dragonfly
images.configure do |c|
c.define_url do |app, job, opts|
thumb = ThumbTracker.where(job: job.serialize).first
unless thumb
uid = job.store
thumb = ThumbTracker.create!(
:uid => uid,
:job => job.serialize
)