Skip to content

Instantly share code, notes, and snippets.

View marktriggs's full-sized avatar
💭
PROGRAMMING

Mark Triggs marktriggs

💭
PROGRAMMING
View GitHub Profile
(defn dumb-split [#^String s c #^"[Ljava.lang.String;" tokens]
(loop [i (int 0)
start (int 0)
end (int 0)]
(cond (>= end (.length s))
(do (aset tokens i (.substring s start end))
tokens)
(= (.charAt s end) c)
(do (aset tokens i (.substring s start end))
;; now even dumber :P
(defn dumbest-split [#^String s c #^"[Ljava.lang.String;" tokens]
(loop [start (int 0)
i (int 0)]
(let [idx (int (.indexOf s (int c) (int start)))]
(if (neg? idx)
(do (aset tokens i (.substring s start))
tokens)
(do (aset tokens i (.substring s start idx))
(with-open [r (BufferedReader. (java.io.InputStreamReader.
(FileInputStream. "/home/mst/updates.xml")
"US-ASCII")
131072)]
(loop [#^String line (.readLine r)
remaining (- end-byte start-byte)]
(when (and (>= remaining 0) line)
(recur (.readLine r)
(- remaining (.length line))))))
(defn count-ips [logfile]
(remove empty?
(persistent! (reduce
#(assoc! %1 %2 (inc (get %1 %2 0)))
(transient {})
(of-IPs
(find-lines "Deny tcp src outside" logfile))))))
/* Not the nicest code we ever wrote... */
<?php
require_once 'HTTP/Request.php';
require_once 'Text/Wiki/Mediawiki.php';
class Wikipedia
{
(import '(org.apache.solr.core CoreContainer CoreContainer$Initializer))
(import '(org.apache.solr.client.solrj.embedded EmbeddedSolrServer))
(import '(org.apache.solr.client.solrj SolrQuery))
(import '(org.apache.solr.common SolrInputDocument))
(System/setProperty "solr.solr.home"
"/home/mst/projects/nyu/sakai/upstream/solr-debugging")
(def core (.initialize (new CoreContainer$Initializer)))
<fieldtype name="initials" class="solr.TextField">
<analyzer>
<tokenizer class="solr.WhitespaceTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="1" side="front"/>
</analyzer>
</fieldtype>
$ rlwrap telnet localhost 4010
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Type ':eof' to exit
>>> scr = reference("org.apache.felix.scr.ScrService")
>>> components = scr.getComponents("org.sakaiproject.nakamura.http.usercontent.ServerProtectionServiceImpl")
<?xml version='1.0' encoding='utf-8'?>
<marcstats record_count='9285'>
<leader>
<position index='6'>
<value count='7971'>a</value>
<value count='111'>c</value>
<value count='1'>d</value>
<value count='1059'>e</value>
<value count='2'>f</value>
<value count='3'>g</value>
#!/bin/bash
# init script for Cassandra.
# chkconfig: 2345 90 10
# description: Cassandra
# script slightly modified from
# http://blog.milford.io/2010/06/installing-apache-cassandra-on-centos/
#
# And further tweaked for Apereo OAE
#
. /etc/rc.d/init.d/functions