Skip to content

Instantly share code, notes, and snippets.

var record = {
id: idgen(20) ,
data: {
ip: parts[0],
agent: parts[1],
url: parts[2],
referrer: parts[3],
mobile: mobile
}
};
<--- Pseudocode --->
db.keyStream.on('data', function(key) {
if (searchTerm is in key)) {
< add key to list of keys found>
}
});
Problems:
Every record must be searched.
@ada-lovecraft
ada-lovecraft / gist:5373157
Last active December 16, 2015 03:49
Current leveldb Implementation vs. Proposed
<!----- Current Implementation ---->
Key | Value
------------------|----------------
keyword|uuid | uuid
------------------------------------
uuid | object{}
| ip,
| agent,
| url,
| referrer,
@ada-lovecraft
ada-lovecraft / dropData.js
Last active December 16, 2015 20:00
Grab text data from dropped item.
$("#dropTarget")
.bind("dragover", false)
.bind("dragenter", function(e) {
// add the "activeDrag" class when dragenter is detected
$(this).addClass('activeDrag');
})
.bind("drop", function(e) {
e.preventDefault();
// grab the text data from the dropped item
var dragData = e.originalEvent.dataTransfer.getData("text") ||
@ada-lovecraft
ada-lovecraft / gist:5489966
Last active December 16, 2015 20:09
RegEx For Snwspeckle
// grabs the values from your html that represent the array for ansMap
((?<=ansMap\[\d] = ')|(?<=ansMap\[\d\d] = '))\w+
@ada-lovecraft
ada-lovecraft / gist:5577496
Created May 14, 2013 16:50
Weird JS Regex.
var links = ["http://i.imgur.com/i2fB61Z.jpg", ""http://i.imgur.com/TJOigM8.jpg"];
links.forEach(function(link) {
var match = null;
match = image.link.match(/http:\/\/i\.imgur\.com\//);
console.log(match);
});
/*** output
http://i.imgur.com/
@ada-lovecraft
ada-lovecraft / excerpt.js
Created May 14, 2013 16:54
An excerpt from the actual code
//spin through each image object
json.data.forEach(function(image,index,array) {
//we don't want gifs
if (!image.link.match(/\.gif$/)) {
//get the image extension
var ext = image.link.match(/\.\w+$/);
//change the link to give us the (l)arge version so we don't kill ourselves on bandwidth
//also remove the http://i.imgur.com/ text from the link
var match = image.link.match(/http:\/\/i\.imgur\.com\//);
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(<[^>]+?>|{{[^}]+?}})" options:0 error:&error];
NSString *result = [regex stringByReplacingMatchesInString:contents options:0 range:NSMakeRange(0, [contents length]) withTemplate:@""];
NSLog(@"%@",result);
@ada-lovecraft
ada-lovecraft / latest.js
Created May 29, 2013 17:29
CouchBase View Sample
function (doc, meta) {
var mostRecentVersion = doc.versions[doc.versions.length -1];
emit(meta.id, {
"title": doc.title,
"byline": doc.byline,
"author": doc.author,
"tags": doc.tags,
"latest": mostRecentVersion
});
}
@ada-lovecraft
ada-lovecraft / post.jade
Created May 29, 2013 18:15
Incorrect: Markdown filter in jade using a string of markdown.
extends layout
block content
h2= post.value.title
h3= post.value.byline
p
:markdown
#{post.value.body}