Skip to content

Instantly share code, notes, and snippets.

@doobrie
doobrie / init.vim
Created January 11, 2022 23:11
NeoVim init.vim
let mapleader = " "
set exrc
set relativenumber
set nu
set nohlsearch
set mouse=a
set hidden
set splitright
set splitbelow
@doobrie
doobrie / Selectors.csv
Last active June 11, 2021 16:03
Common Selectors
Selector Description
* Selects all elements
element Selects all elements of type 'element' e.g. h1 or p
el1 comma el2 Selects all elements of the specified type e.g. h1 or h2
el1 el2 Selects all elements of type 'el2' inside elements of type 'el1' e.g. div p selects all 'p' within 'div'
el1 > el2 Selects all elements of type 'el2' where 'el1' is the direct parent e.g. div > p selects all 'p' with parents 'div'
.cls Selects elements with the class 'cls'
.cls1.cls2 Selects elements with class 'cls1' and 'cls2' e.g. .task.information
#id Selects elements with the id 'id'
element.class Selects elements of type 'element' with class '.class' e.g. p.information
@doobrie
doobrie / CappedCollection.js
Created June 11, 2021 13:59
Check Collection Status
> db.cappedLogsJavaDriver.stats()
{
"ns" : "test.cappedLogsJavaDriver",
"count" : 5,
"size" : 180,
"avgObjSize" : 36,
"storageSize" : 4096,
"numExtents" : 1,
"nindexes" : 1,
"lastExtentSize" : 4096,
@doobrie
doobrie / CappedCollection.java
Created June 11, 2021 13:59
Insert Entries using Mprphia
for (int i = 0; i < 8; i++) {
LogEntry logEntry = new LogEntry(i);
datastore.save(logEntry);
}
@doobrie
doobrie / CappedCollection.js
Created June 11, 2021 13:58
Open Capped Collection Using Morphia
MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost"));
DB db = mongoClient.getDB("test");
Morphia morphia = new Morphia();
morphia.map(LogEntry.class);
Datastore datastore = morphia.createDatastore(mongoClient, "test");
datastore.ensureCaps();
@doobrie
doobrie / LogEntry.java
Created June 11, 2021 13:57
Morphia Entity
@Entity(value="cappedLogsMorphia", cap=@CappedAt(count=5, value=4096))
public class LogEntry {
private int logId;
@Id
private ObjectId id;
public LogEntry(int logId) {
this.logId = logId;
@doobrie
doobrie / CappedCollection.js
Created June 11, 2021 13:55
Query Capped Collection Via Mongo
> db.cappedLogsJavaDriver.find()
{ "_id" : ObjectId("54a1ca44a82617da4f72e025"), "logId" : 3 }
{ "_id" : ObjectId("54a1ca44a82617da4f72e026"), "logId" : 4 }
{ "_id" : ObjectId("54a1ca44a82617da4f72e027"), "logId" : 5 }
{ "_id" : ObjectId("54a1ca44a82617da4f72e028"), "logId" : 6 }
{ "_id" : ObjectId("54a1ca44a82617da4f72e029"), "logId" : 7 }
@doobrie
doobrie / CappedCollection.java
Created June 11, 2021 13:54
Create 8 Objects in Capped Collection
for (int i = 0; i < 8; i++) {
BasicDBObject logEntry = new BasicDBObject("logId", i);
collection.insert(logEntry);
}
@doobrie
doobrie / CappedCollection.java
Created June 11, 2021 13:53
Create Capped Collection Using Java Driver
MongoClient mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost"));
DB db = mongoClient.getDB("test");
DBCollection collection;
if (!db.collectionExists("cappedLogsJavaDriver")) {
BasicDBObject options = new BasicDBObject("capped", true);
options.append("size", 4096);
options.append("max", 5);
collection = db.createCollection("cappedLogsJavaDriver", options);
} else {
@doobrie
doobrie / CappedCollection.java
Created June 11, 2021 13:48
Create MongoDB Capped Collection
db.createCollection("logs", {capped: true,
size: 4096,
max:5})