Skip to content

Instantly share code, notes, and snippets.

@charles-dyfis-net
charles-dyfis-net / gist:2912188
Created June 11, 2012 19:38
Trawling Clojure's thread-local frames
(ns thread-utils)
(def ^:private frame-prev-field (doto (.getDeclaredField clojure.lang.Var$Frame "prev") (.setAccessible true)))
(def ^:private bindings-field (doto (.getDeclaredField clojure.lang.Var$Frame "bindings") (.setAccessible true)))
(def ^:private tbox-val-field (doto (.getDeclaredField clojure.lang.Var$TBox "val") (.setAccessible true)))
(def ^:private thread-locals-field (doto (.getDeclaredField Thread "threadLocals") (.setAccessible true)))
(def ^:private thread-local-map-field (doto (.getDeclaredField java.lang.ThreadLocal$ThreadLocalMap "table") (.setAccessible true)))
(def ^:private entry-value-field (doto (.getDeclaredField java.lang.ThreadLocal$ThreadLocalMap$Entry "value") (.setAccessible true)))
(defn all-threads []
@charles-dyfis-net
charles-dyfis-net / gist:2909106
Created June 11, 2012 08:39
clojure.osgi aware nREPL middleware
(defn osgi-bundle-handler
"If the namespace currently associated with this REPL has an OSGi
bundle associated, use this to set osgi/*bundle* and
clojure.lang.Compiler/LOADER."
[h]
(fn [msg]
(let [ns-meta (meta (get (deref (:session msg)) #'clojure.core/*ns*))
bundle (and ns-meta (:clojure.osgi.core/bundle ns-meta))
classloader (or (:repl-classloader ns-meta)
(and bundle (osgi/bundle-class-loader bundle)))
@charles-dyfis-net
charles-dyfis-net / gist:1424448
Created December 2, 2011 19:09
uWSGI thread dump trigger
# added in WSGI handler run by uUWSGI
import sys
import os.path
try:
import uwsgi
import threading
stack_dump_file = '/tmp/stack-dump-trigger' ## given as an example; put this somewhere better than /tmp
@charles-dyfis-net
charles-dyfis-net / template_tracing.py
Created September 6, 2011 21:13
Example of instrumenting jinja2 to trace template components
import contextlib
@contextlib.contextmanager
def trace_to_stderr(name):
"""Trivial proof-of-concept for tracing template rendering"""
print >>sys.stderr, 'ENTER: %s' % (name,)
yield
print >>sys.stderr, 'EXIT: %s' % (name,)
class trace_decorator(object):
def __init__(self, contextmgr_type, item_type, item_name, *args, **kwargs):
@charles-dyfis-net
charles-dyfis-net / definition.rb
Created July 24, 2011 19:33
CentOS-6.0 (i386) + RBEL Chef veewee definition
Veewee::Session.declare( {
:cpu_count => '1', :memory_size=> '384',
:disk_size => '10140', :disk_format => 'VDI',
:os_type_id => 'RedHat',
:iso_file => "CentOS-6.0-i386-bin-DVD.iso", :iso_src => "", :iso_md5 => "d7e57d6edaca1556d5bad2fa88602309", :iso_download_timeout => 1000,
:boot_wait => "10",:boot_cmd_sequence => ['<Esc>', 'linux text ks=http://%IP%:%PORT%/ks.cfg<Enter>'],
:kickstart_port => "7122", :kickstart_timeout => 10000,:kickstart_file => "ks.cfg",
:ssh_login_timeout => "100",:ssh_user => "vagrant", :ssh_password => "vagrant",:ssh_key => "",
:ssh_host_port => "7222", :ssh_guest_port => "22",
:sudo_cmd => "echo '%p'|sudo -S sh '%f'",
@charles-dyfis-net
charles-dyfis-net / gist:1081213
Created July 13, 2011 20:13
trying to install vagrant and dependencies inside an rvm environment
$ rvm gemset create vagrant
'vagrant' gemset created (/home/cduffy/.rvm/gems/ruby-1.8.7-p352@vagrant).
$ rvm gemset use vagrant
$ cd ~/VC/vagrant
~/VC/vagrant$ gem install bundler --pre
Fetching: bundler-1.1.pre.5.gem (100%)
Successfully installed bundler-1.1.pre.5
1 gem installed
Installing ri documentation for bundler-1.1.pre.5...
Installing RDoc documentation for bundler-1.1.pre.5...
@charles-dyfis-net
charles-dyfis-net / gist:1069905
Created July 7, 2011 16:26
hashing the certificates in a bundle
reading=0
while read; do
if [[ $REPLY = *BEGIN* ]]; then
current_cert=""
reading=1
fi
if (( reading )) ; then
current_cert+="$REPLY"$'\n'
fi
#!/bin/bash
while read -r diff
do
echo "$diff"
done < <(comm -12 <(sort db) <(sort dbnew)))
@charles-dyfis-net
charles-dyfis-net / parse-certs
Created June 23, 2011 19:34
Mozilla certdata.txt -> ca-bundle.crt parser
#!/bin/bash
#
# Parse Mozilla's certdata.txt and extract CA Root Certificates into PEM
# format.
#
# Based on http://curl.haxx.se/mail/lib-2004-07/0134.html; cleaned up to
# follow fewer worst practices for bash :)
#
# certdata.txt can be found in Mozilla's source tree:
# /mozilla/security/nss/lib/ckfw/builtins/certdata.txt
@charles-dyfis-net
charles-dyfis-net / nodejs.spec
Created March 1, 2011 12:15
node.js spec for CentOS 5
#node is an already known package. node.js have dot in name, so "nodejs"
#is a better name
#some ideas are taken from
#http://blog.fpmurphy.com/2010/12/node-js-and-npm-on-fedora-14.html
Name: nodejs
Version: 0.4.0
Release: 0%{?dist}
Summary: JavaScript server-side network application development
Group: Development/Languages/Other
License: MIT