Cleaner proto

This commit is contained in:
Phyks 2014-10-28 22:30:24 +01:00
parent acc396cdfe
commit afaa2e3d42
8 changed files with 52 additions and 24 deletions

BIN
bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

5
css/bootstrap.min.css vendored Normal file

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -1 +1 @@
{"index": ["../samples/cryptdevice_multi.html", "../samples/highmon_weechat.html"]}
{"index": [{"title": "Decrypt multiple LUKS containers at boot on Arch", "url": "samples/cryptdevice_multi.html"}, {"title": "Hilight window in weechat", "url": "samples/highmon_weechat.html"}]}

View File

@ -2,21 +2,35 @@
<html lang="fr">
<head>
<meta charset="utf-8">
<title>BloomJS demo</title>
<title>BloomySearch</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style type="text/css">
#error {
font-weight: bold;
color: red;
body {
background-image: url('bg.png');
}
html, body {
height: 100%;
}
.container {
background-color: white;
min-height: 100%;
}
</style>
</head>
<body>
<h1>Bloom.JS demo</h1>
<div class="container">
<h1 class="text-right">BloomySearch</h1>
<hr/>
<p id="error"></p>
<div id="main">
<p>Loading…</p>
<p class="alert alert-info">Loading…</p>
</div>
<div id="results"></div>
<h2 class="text-right" style="margin-top: 3em;">More about BloomySearch</h2>
<hr/>
</div>
<script type="text/javascript" src="js/bloom.js"></script>
<script type="text/javascript" src="js/stemmer.js"></script>
<script type="text/javascript" src="js/app.js"></script>

View File

@ -123,10 +123,9 @@ class BloomFilter():
http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
"""
v -= ctypes.c_int(ctypes.c_int(v >> 1).value & ctypes.c_int(0x55555555).value).value
v = ctypes.c_int(v & 0x33333333).value + c_types.c_int(ctypes.c_int(v >> 2).value & 0x33333333).value
v = ctypes.c_int(v & 0x33333333).value + ctypes.c_int(ctypes.c_int(v >> 2).value & 0x33333333).value
return ctypes.c_int((ctypes.c_int((v + ctypes.c_int(v >> 4).value) & 0xF0F0F0F).value * 0x1010101) >> 24).value
def rshift(self, val, n):
"""
Implements the >>> JS operator.

View File

@ -36,7 +36,10 @@ def remove_common_words(words):
if __name__ == "__main__":
error_rate = 0.1
os.chdir(os.path.dirname(sys.argv[0]))
samples = list_directory("../samples/")
pages = []
filters = []
p = stemmer.PorterStemmer()
@ -58,12 +61,14 @@ if __name__ == "__main__":
tmp_filter = bloom.BloomFilter(capacity=len(words),
error_rate=error_rate)
words = json.loads('["solut", "devic", "cryptkey2", "contain", "chang", "thi", "conf", "ckeyfiin", "support", "load", "here", "laptop", "file", "exampl", "paramet", "cryptsetup", "when", "proce", "line", "cryptkei", "wiki", "edit", "present", "describ", "ckei", "grub", "first", "warn", "mkinitcpio", "with", "updat", "mount", "manual", "ckeybyif", "least", "need", "multipl", "also", "found", "arch", "then", "us", "encrypt", "packag", "that", "over", "someth", "hook", "doesn", "avail", "avoid", "work", "which", "provid", "order", "initcpio", "anoth", "setup", "mean", "necessari", "default", "disk", "best", "linemkdir", "luk", "system", "unlock", "occurr", "requir", "command", "abl", "cryptdevice2", "encrypt2", "instal", "multi", "last", "extend", "obsolet", "boot", "your", "achiev", "second", "mkdir", "stuff", "final", "displai", "concern", "ad", "cryptdevic", "more", "copi"]')
for word in words:
tmp_filter.add(word)
filters.append(tmp_filter.buckets)
pages.append({"title": re.search(r"@title=(.*)\n", content).group(1),
"url": sample[3:]})
# First Int32 is length
filters_to_write = struct.pack("<i", len(filters))
# Then comes the length of each filter
@ -78,4 +83,4 @@ if __name__ == "__main__":
index_fh.write(filters_to_write)
with open("../data/pages.json", "w") as pages_fh:
pages_fh.write(json.dumps({"index": samples}))
pages_fh.write(json.dumps({"index": pages}))

View File

@ -15,7 +15,7 @@ function callback() {
// Sets up the page, that is now ready
ready = true;
document.getElementById('main').innerHTML = '<form id="search_form"><p><input type="text" id="search" name="search" placeholder="Search for articles..."/></p></form>';
document.getElementById('main').innerHTML = '<form role="form" id="search_form"><p class="form-group"><label for="search">What are you thinking about?</label><input class="form-control" type="text" id="search" name="search" placeholder="Type something to search for…"/></p></form>';
// Handle onchange actions
document.getElementById('search').oninput = function (e) {
@ -23,8 +23,13 @@ function callback() {
return;
}
if (e.target.value !== "") {
filter_results(e.target.value);
}
else {
document.getElementById("results").innerHTML = "";
}
}
}
// Returns true iff all the terms in the array are in the bloom filter b
@ -53,14 +58,14 @@ function filter_results(query) {
}
if (results.length > 0) {
results_html = '<ul>';
results_html = '<h4>' + results.length + ' results found:</h4><div>';
for (var i = 0; i < results.length; i++) {
results_html += '<li>' + results[i] + '</li>';
results_html += '<a href="' + results[i]["url"] + '" class="list-group-item">' + results[i]["title"] + '</a>';
}
results_html += '</ul>'
results_html += '</div>'
}
else {
results_html = '<p>Aucun résultat.</p>';
results_html = '<p class="alert alert-danger">No results found =(</p>';
}
document.getElementById('results').innerHTML = results_html;
}
@ -90,14 +95,14 @@ oReq.onload = function (oEvent) {
tmp_array = byte_array.subarray(1 + nb_bloom_filters + l, 1 + nb_bloom_filters + l + lengths[i]);
var l = lengths[i];
bloom.push(new BloomFilter(tmp_array, error_rate));
console.log(tmp_array);
console.log(bloom[0].test("concern"));
}
callback();
}
else {
document.getElementById('error').innerHTML = 'Unable to load the bloom filters.';
var error = document.getElementById('error');
error.innerHTML = 'Unable to load the bloom filters.';
error.className = "alert alert-danger";
}
};
oReq.send(null);