Skip to content

Instantly share code, notes, and snippets.

@csm
csm / README
Created January 24, 2021 23:30
Start a in-memory S3-compatible (kinda...) server.
Uses https://github.com/csm/s4
(defn distinct-by
"Like distinct, but uses f to consider what duplicate values are."
([f]
(fn [rf]
(let [seen (volatile! #{})]
(fn
([] (rf))
([result] (rf result))
([result input]
(let [v (f input)]
@csm
csm / recyclable.clj
Last active September 14, 2017 19:29
(import '[io.netty.util Recycler])
(defprotocol Recyclable
(recycle! [this] "Recycles this object."))
(defprotocol Init
(init! [this values]))
(defmacro defrecyclable
[name fields & {:keys [max-capacity] :or {max-capacity 8096}}]
(defn js-engine
[]
(if-let [engine (.getEngineByName (ScriptEngineManager.) "JavaScript")]
engine
(throw (Exception. "no JavaScript engine found. Sorry"))))
(defn run-slides-js
[s]
(let [engine (js-engine)
script (str "(function() {\n"
import java.io.*;
import java.net.*;
public class NetTest {
public static void main(String[] argv) throws Throwable {
Socket socket = new Socket();
try {
System.out.println("connecting socket...");
socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 31337));
socket.connect(new InetSocketAddress(InetAddress.getByName(argv[0]), 4242));
@csm
csm / Log output
Last active August 29, 2015 14:14
Exception running nodetool decommission, Cassandra 2.0.11.82 (DSE 4.5.3)
INFO [CompactionExecutor:113] 2015-02-04 22:11:22,600 CompactionTask.java (line 115) Compacting [SSTableReader(path='x'), SSTableReader(path='x'), SSTableReader(path='x'), SSTableReader(path='x')]
INFO [CompactionExecutor:113] 2015-02-04 22:11:22,639 CompactionTask.java (line 287) Compacted 4 sstables to [x,]. 36,329 bytes to 11,065 (~30% of original) in 37ms = 0.285200MB/s. 1,039 total partitions merged to 280. Partition merge counts were {1:159, 2:53, 3:258, }
INFO [RMI TCP Connection(1642)-x] 2015-02-04 22:11:22,670 StorageService.java (line 970) DRAINED
ERROR [CompactionExecutor:114] 2015-02-04 22:11:22,679 CassandraDaemon.java (line 199) Exception in thread Thread[CompactionExecutor:114,1,RMI Runtime]
java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@45ad7114 rejected from org.apache.cassandra.concurrent.DebuggableScheduledThreadPoolExecutor@7ddafbc8[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed ta
@csm
csm / zen.sh
Created January 31, 2015 00:09
Continuous compilation of Grafana
#!/bin/bash
while true; do
until grunt build; do
fswatch -1 src/
done
grunt server &
new_job_started="$(jobs -n)"
if [ -n "$new_job_started" ];then
server_pid=$!
@csm
csm / snippet.diff
Last active November 26, 2022 20:46
Apple's SSL bug; diff between last known-good (OS X 10.8.5) and known-bad (OS X 10.9)
@@ -596,8 +597,8 @@
dataToSignLen = SSL_SHA1_DIGEST_LEN + SSL_MD5_DIGEST_LEN;
hashOut.data = hashes;
hashOut.length = SSL_MD5_DIGEST_LEN;
-
- if ((err = ReadyHash(&SSLHashMD5, &hashCtx, ctx)) != 0)
+
+ if ((err = ReadyHash(&SSLHashMD5, &hashCtx)) != 0)
goto fail;
if ((err = SSLHashMD5.update(&hashCtx, &clientRandom)) != 0)
@csm
csm / lintest.py
Created October 4, 2012 22:53
Linear hashing example
import collections
import random
i = 0
n = 0
d = [collections.OrderedDict()]
def lin(k):
global i
@csm
csm / gist:2483382
Created April 24, 2012 20:22
CouchDB invocation error
Command line invocation:
/Users/csm/Library/Developer/Xcode/DerivedData/Magni-fofbzndvghoaitbkravzhufuwzey/Build/Products/Debug/X\ Y.app/Contents/Resources/CouchDB/Versions/1.2/Resources/bin/erl +Bd -noinput -os_mon start_memsup false start_cpu_sup false disk_space_check_interval 1 disk_almost_full_threshold 1 -sasl errlog_type error +K true +A 4 -env ERL_LIBS /Users/csm/Library/Developer/Xcode/DerivedData/Magni-fofbzndvghoaitbkravzhufuwzey/Build/Products/Debug/X\ Y.app/Contents/Resources/CouchDB/Versions/1.2/Resources/lib/couchdb/erlang/lib -couch_ini /Users/csm/Library/Developer/Xcode/DerivedData/Magni-fofbzndvghoaitbkravzhufuwzey/Build/Products/Debug/X\ Y.app/Contents/Resources/CouchDB/Versions/1.2/Resources/etc/couchdb/default.ini /Users/csm/Library/Developer/Xcode/DerivedData/Magni-fofbzndvghoaitbkravzhufuwzey/Build/Products/Debug/X\ Y.app/Contents/Resources/CouchDB/Versions/1.2/Resources/etc/couchdb/local.ini /Users/csm/Library/Application Support/Memeo\ C1/local.ini -s couch
Output:
{"init terminati