Skip to content

Instantly share code, notes, and snippets.

@vmx
vmx / display-all-changes.js
Created May 26, 2013 18:47
Bookmarklet for Gerrit that displays all changesets for a certain Change-Id. This way you can link commits across different projects.
function getChangeId(container) {
for (var i in container.childNodes) {
var node = container.childNodes[i];
if (node.nodeName === 'P' &&
node.innerText.indexOf('Change-Id:') === 0) {
var changeId = node.innerText.substr('Change-Id: '.length, 41);
return changeId;
}
}
return 'error';
@vmx
vmx / gist:6095160
Last active December 20, 2015 07:39
Creates directories if they didn't exist before the file is moved. This script is meant to be uses in conjunction with `qmv`. That way it's possible to rename files from foo.txt -> bar/baz.txt. Just run qmv as `qmv --command=pmv.py`
#!/usr/bin/env python3
# pmv.py - Creates directories if they didn't exist before the file is moved
# Written in 2013 by Volker Mische <volker.mische@gmail.com>
#
# To the extent possible under law, the author(s) have dedicated all copyright
# and related and neighboring rights to this software to the public domain
# worldwide. This software is distributed without any warranty.
#
# You should have received a copy of the CC0 Public Domain Dedication along
# with this software. If not, see
@vmx
vmx / gist:6231565
Last active December 21, 2015 01:58
This is how an implementation of the Read Your Own Writes could look like on the application level.

Read Your Own Write implementation specification

This specification outlines the details on how Read Your Own Write (RYOW). The provided code will be using reflect how an implementation in Python might look like.

Client/server architecture

Throughout the spec there's a common architecture of the system, that consists of three parts:

@vmx
vmx / couchbase-index-updater.md
Last active December 22, 2015 05:29
Couchbase view engine index updater

Couchbase view engine index updater

This is a blog post about the internals of the Couchbase view engine index updater.

The index updater is triggered

The updater is triggered whenever a view query is performed and there is data available that isn't already indexed. Just imagine that you've inserted some data and now query a view with stale=false.

@vmx
vmx / spatial-android.diff
Created September 17, 2013 11:50
This is what I hacked together in June. I don't think it works, but you perhaps get some idea.
diff --git a/CouchbaseLiteProject/.idea/libraries/CBLite_aar.xml b/CouchbaseLiteProject/.idea/libraries/CBLite_aar.xml
index 0a46271..fad1f82 100644
--- a/CouchbaseLiteProject/.idea/libraries/CBLite_aar.xml
+++ b/CouchbaseLiteProject/.idea/libraries/CBLite_aar.xml
@@ -2,6 +2,8 @@
<library name="CBLite.aar">
<CLASSES>
<root url="jar://$PROJECT_DIR$/CBLiteEktorp/build/exploded-bundles/CBLite.aar/classes.jar!/" />
+ <root url="jar://$PROJECT_DIR$/CBLiteJavascript/build/exploded-bundles/CBLite.aar/classes.jar!/" />
+ <root url="jar://$PROJECT_DIR$/CBLiteListener/build/exploded-bundles/CBLite.aar/classes.jar!/" />
@vmx
vmx / gist:7521098
Last active December 28, 2015 15:19
Rationalize implementation for Rust based on the Clisp one.
extern mod extra;
use std::cast;
use std::num::{One, Zero};
use extra::rational::BigRational;
use extra::rational::Ratio;
use extra::bigint::{BigInt, BigUint, Sign, Plus, Minus};
// Ported from
// http://www.javadocexamples.com/java_source/org/armedbear/lisp/FloatFunctions.java.html
@vmx
vmx / gist:8344286
Last active January 5, 2020 23:02
Rust Macro for assert for pattern matching
macro_rules! assert_match(
($given:expr , $expected:ident) => (
match $given {
$expected => {},
_ => fail!("assertion failed: no match (given: `{:?}`, expected: `{:s}`)",
$given, stringify!($expected))
}
);
)
#!/usr/bin/env python
"""
Prints all the builds in the queue that are from the same Gerrit change
number, but have another more recent patch set in the queue. It also
prints all changes with a ref change which isn't a new patch set.
You can abort all the builds that are returned in case you don't want to
test outdated patch sets. The return value is the queue ID, e.g. '1234'.
Such a build in the queue can then be cancled with a POST to
@vmx
vmx / cbupr.lua
Last active August 29, 2015 14:00
Additional parsing for the Couchbase UPR protocol in Wireshark
-- NOTE: This is GPLv2 because it uses the Wireshark API
-- This program is free software; you can redistribute it and/or
-- modify it under the terms of the GNU General Public License
-- as published by the Free Software Foundation; either version 2
-- of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@vmx
vmx / gist:669587813844e5b23325
Created July 1, 2014 02:13
Monitoring memory usage within Couchbase
curl -X POST -d 'Json = lists:map(fun(P) -> Info = process_info(P, [current_function, total_heap_size, memory, message_queue_len, reductions, stack_size, status]), Info2 = lists:map(fun(I) -> case I of {current_function, {Mod, Name, Arit}=CF} -> {current_function, list_to_binary(io_lib:format("~p:~p/~p", tuple_to_list(CF)))}; _ -> I end end, Info), {struct, Info2} end, erlang:processes()), {json, Json}' http://localhost:9000/diag/eval