Skip to content

Instantly share code, notes, and snippets.

View zentrope's full-sized avatar

Keith Irwin zentrope

  • Portland, Oregon
View GitHub Profile
@zentrope
zentrope / bytes_to_int.clj
Created January 11, 2012 00:22
bytes->int clojure
;; Surely I can do better than this.
(defn- ^BigInteger bytes->int
[^bytes bytes & {:keys [little-endian]
:or {little-endian true}}]
(let [b (if little-endian (reverse bytes) bytes)]
(->> b
(cons (byte 0))
(byte-array)
(biginteger))))
@zentrope
zentrope / gist:2228433
Created March 28, 2012 17:26
homebrew mysql 5.1 failure
Homebrew 0.9
==> Downloading http://mysql.mirrors.pair.com/Downloads/MySQL-5.1/mysql-5.1.58.tar.gz
Already downloaded: /Library/Caches/Homebrew/mysql51-5.1.58.tar.gz
/usr/bin/tar xf /Library/Caches/Homebrew/mysql51-5.1.58.tar.gz
==> Patching
/usr/bin/patch -f -p1 -i 000-homebrew.diff
patching file scripts/mysqld_safe.sh
Hunk #1 succeeded at 384 (offset 1 line).
patching file scripts/mysql_config.sh
==> ./configure --without-docs --without-debug --disable-dependency-tracking --prefix=/usr/local/Cellar/mysql51/5.1.58 --localstatedir=/usr/local/var/mysql --sysconfdir=/usr/local/etc --with-plugins=innobase,myisam --with-extra-charsets=complex --with-ssl --without-readline --enable-assembler --enable-thread-safe-client --enable-local-infile --enable-shared --with-partition
@zentrope
zentrope / sql_builder.clj
Created June 26, 2012 01:08
fun with clojure defmulti and sql
;; Just some random REPL experiments I wanted to safe in case I want to make
;; the mistake of building an SQL query generator.
(require '[clojure.string :as string])
(defmulti sql-op type)
(defmethod sql-op Long [_] "=")
(defmethod sql-op String [_] "=")
(defmethod sql-op java.util.List [_] "in")
@zentrope
zentrope / db.clj
Created June 26, 2012 22:57
Ongoing experiments with DB layers in Clojure
(ns task-web.models.db
(:require [clojure.tools.logging :as log]
[clojure.java.jdbc :as sql]
[clojure.string :as string]))
(declare scrub)
;;-----------------------------------------------------------------------------
;; UTILS
;;-----------------------------------------------------------------------------
@zentrope
zentrope / unintern-example.clj
Created August 29, 2012 04:10
Unintern Symbol in Clojure
;; How do you undef / unintern a symbol in Clojure?
(ns-unmap 'namespace 'symbol)
@zentrope
zentrope / bashrc.sh
Created September 10, 2012 00:01
PS1
bold="\[\033[01m\]"
off="\[\033[0m\]"
blue="\[\033[0;34m\]"
red="\[\033[0;31m\]"
light_red="\[\033[1;31m\]"
green="\[\033[0;32m\]"
lgreen="\[\033[1;32m\]"
white="\[\033[1;37m\]"
@zentrope
zentrope / core.clj
Created December 7, 2012 19:05
JMX Example
(ns jmxican.core
(:require
[clojure.java.jmx :as jmx]))
;;-----------------------------------------------------------------------------
;; Little ditty to keep the app up and running until
;; we get an OS signal to shut down.
;;-----------------------------------------------------------------------------
(let [lock (promise)]
@zentrope
zentrope / cipher.sh
Last active October 21, 2015 04:06
nginx, mont and shell for running and monitoring a java process on a unix (FreeBSD) system
#!/bin/sh
app="cipher"
version="0.9.2"
java="/usr/local/bin/java"
daemon="/usr/sbin/daemon"
app_home="/home/vagrant/apps/${app}"
jar="${app}-${version}-standalone.jar"
@zentrope
zentrope / Vagrantfile
Created October 23, 2015 03:50
Vagrant file for FreeBSD on OS X
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
config.vm.guest = :freebsd
config.vm.box = "freebsd/FreeBSD-10.2-RELEASE"
@zentrope
zentrope / get-bars.clj
Last active December 12, 2015 03:32
Stringing out XML blobs
#!/usr/bin/env clj
(defn get-bars
[xml]
(loop [xml xml
bars []]
(if (clojure.string/blank? xml)
bars
(let [[_ bar xml2 :as r] (clojure.string/split xml #"<bar>|</bar>" 3)]
(if (nil? bar)