Skip to content

Instantly share code, notes, and snippets.

module ActiveRecord::Associations::ClassMethods
%w{has_and_belongs_to_many has_many has_one}.each do |meth|
eval(<<METHOD_OVERRIDE
# intercepting the #{meth} method to add the :as_component option
def #{meth}_with_component(name, options = {})
if options.delete(:as_component)
options[:after_add] = :tell_my_parents
self.components ||= []
self.components << name
end
(defn del-sec
"Delete a line or section from the lst. Optional second argument
will force single line deletion rather than deleting an entire
section."
([lst]
(let [start (rand-int (.size lst))
length (rand-int (- (.size lst) start))]
(concat (take start lst) (drop (+ start length) lst))))
([lst single]
(let [start (rand-int (.size lst))]

this is a simple test

(require 'mmm-mode)
#name {
  float: center;
Exception in thread "main" Unable to resolve artifact: Unable to get dependency information: Unable to read the metadata file for artifact 'incanter:incanter-full:jar': Cannot find parent: incanter:incanter-parent for project: incanter:incanter-full:bundle:1.0-master-SNAPSHOT for project incanter:incanter-full:bundle:1.0-master-SNAPSHOT
incanter:incanter-full:jar:1.0-master-SNAPSHOT
(add-to-list 'load-path "~/src/emacs-starter-kit/src/mmm-mode")
(require 'mmm-mode)
(setq mmm-global-mode 'maybe)
(mmm-add-classes
'((embedded-org-css
:submode css
:face mmm-declaration-submode-face
:delimiter-mode nil
:front "#\\+begin_src css"
#name : #+begin_...#+end_
# expand-env: ((yas/indent-line 'fixed) (yas/wrap-around-region 'nil))
# --
#+begin_$1 $2
$0
#+end_$1
;; how to use an imperative library (bcel) in clojure
(defn list-expand [asm]
;; I need a mutable InstructionList
(with-local-vars [lst (new InstructionList)]
;; Append is an InstructionList method on which alters the calling
;; InstructionList through side effects
(map #(.append (var-get lst) %) asm)
(var-get lst)))
(defun sinatra-web-server (&optional edit-cmd-args)
"Run script/server. Dump output to a compilation buffer
allowing jumping between errors and source code. With optional
prefix argument allows editing of the server command arguments."
(interactive "P")
(let* ((script (buffer-file-name))
(command (if edit-cmd-args
(read-string "Run Ruby: " (concat script " "))
script)))
(ruby-compilation-run command)))
#!/usr/bin/env ruby
## reap long-running processes and all of their descendants
##
## (?_^
## |\ )
## |/_\
##
def variants
%x{ps auxwww |grep -i "tmp/variant"}.split("\n").map{|l| $1 if l.match(/^[\S]+[\s]+([\d]+)[\s]+/)}.compact
end
;; from Nurullah Akkaya's gist at http://gist.github.com/399127
(ns scraper
(:use [clojure.contrib.duck-streams :only [spit]]
[clojure.contrib.seq-utils :only [partition-all]])
(:import (java.net URL)
(java.io BufferedReader InputStreamReader FileReader)
java.util.Date java.text.SimpleDateFormat))
(defn scrape [url]
(try