Skip to content

Instantly share code, notes, and snippets.

View sjl's full-sized avatar

Steve Losh sjl

View GitHub Profile
@sjl
sjl / gist:1123495
Created August 3, 2011 19:03
http://pbrisbin.com/posts/two_accounts_in_mutt -- Saving a copy because the site seems down and I don't know how long google cache lasts.
This is Google's cache of http://pbrisbin.com/posts/two_accounts_in_mutt. It is a snapshot of the page as it appeared on Jul 29, 2011 07:20:00 GMT. The current page could have changed in the meantime. Learn more
Text-only version
home / all posts / two accounts in mutt
home
about
all posts
@sjl
sjl / gist:1143374
Created August 13, 2011 01:41
Clojurecraft Respawn Handler
(def bot (clojurecraft.core/connect clojurecraft.core/minecraft-local "timmy"))
(defn dead-handler [bot]
[(clojurecraft.actions/chat bot "WHY YOU DO THIS???")
(clojurecraft.actions/respawn bot)])
(clojurecraft.events/add-handler bot :dead #'dead-handler)
@sjl
sjl / gist:1145127
Created August 14, 2011 17:56
Golden Ratio Vim Plugin Comments

There's some weirdness when I've got 3 or more vertical windows open: http://www.screenr.com/cghs

A little animated gif or screencast demo in the readme would be awesome.

I wouldn't bind to <leader>g automatically -- it wiped out what I already had bound to that and I had to rebind the GR key to fix it. At the very least, don't bind to <leader>g if <leader>g is already bound. Actually I'd probably prefer to not have it bound to a key at all by default, since by default there are autocommands so you never need to use the key anyway. If someone disables those autocommands they'll be adding to their Vimrc anyway, so they can just bind whatever key they want at the same time.

One other thing: an option to automatically setlocal wrap on the focused window and setlocal nowrap on all the others would be great.

@sjl
sjl / giver.clj
Created August 14, 2011 21:54
Clojurecraft Givebot
(ns bots.giver
(:require (clojure.contrib [string :as s]))
(:require (clojurecraft [core :as core]
[actions :as actions]
[events :as events])))
(def item-map {"tnt" "46", "lever" "69"})
(def WANT-RE #"^<(\w+)> i want (\d+)? ?(.+)?$")
@sjl
sjl / gist:1149787
Created August 16, 2011 18:28
Clojure Delay + GC Question
(defn random-byte-array
"Return a large byte-array of random bytes."
[]
(byte-array (map byte
(take (* 1024 100)
(cycle [(rand-int 100) (rand-int 100) (rand-int 100)])))))
(defn dtest [arr]
(delay (alength arr)))
@sjl
sjl / next_motion_mapping.vim
Created August 25, 2011 19:43 — forked from AndrewRadev/LICENSE
Execute a vim motion on the "next" text object
" Motion for "next/last object". For example, "din(" would go to the next "()" pair
" and delete its contents.
onoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
xnoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
onoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
xnoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
onoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
xnoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
diff --git a/src/clojurecraft/in.clj b/src/clojurecraft/in.clj
--- a/src/clojurecraft/in.clj
+++ b/src/clojurecraft/in.clj
@@ -461,11 +461,12 @@
is-full-chunk (= FULL-CHUNK chunk-size)
chunk-coords (coords-of-chunk-containing (:x postdata) (:z postdata))]
(dosync (alter (:chunks (:world bot))
assoc chunk-coords (if is-full-chunk
(ref (delay (-chunk-from-full-data postdata)))
- (ref (-chunk-from-partial-data bot postdata))))))))
@sjl
sjl / email.py
Created September 8, 2011 15:15
Useful Django send_mail wrapper that will automatically add a plain text alternative to outgoing HTML emails.
from django.conf import settings
from django.core.mail import EmailMultiAlternatives
from django.template.defaultfilters import striptags
def send_mail(subject, html_message, from_email, recipient_list, fail_silently=False, connection=None):
text_message = striptags(html_message)
recipient_list = getattr(settings, 'EMAIL_RECIPIENTS_OVERRIDE', recipient_list)
msg = EmailMultiAlternatives(subject, text_message, from_email, recipient_list, connection=connection)
msg.attach_alternative(html_message, "text/html")
@sjl
sjl / urls.py
Created September 23, 2011 15:39
Monkeypatch the Celery admin to show a column for task run time in the list view.
# Put this in your urls.py file after the admin.autodiscover() line.
# ---------------------------------------------------------------------------------
# Monkeypatch the Celery admin to show a column for task run time in the list view.
from djcelery.admin import TaskMonitor
from djcelery.models import TaskState
admin.site.unregister([TaskState])
TaskMonitor.list_display += ('runtime',)
admin.site.register(TaskState, TaskMonitor)
@sjl
sjl / gist:1240857
Created September 25, 2011 17:16
Snow Leopard-compiled DVTM binaries (for Lion users)