Skip to content

Instantly share code, notes, and snippets.

#coding: utf-8
from bottle import route, error, post, get, run, static_file, abort, redirect, response, request, template
@route('/')
@route('/index.html')
def index():
return '<a href="/hello">Go to Hello World page</a>'
@route('/hello')
def hello():
@ashutoshraina
ashutoshraina / TailOplog
Created January 2, 2014 10:35
How to tail the mongodb oplog in C# ?
public void GetLastEntryInOpLog()
{
BsonValue lastId = BsonMinKey.Value;
var query = Query.GT("ts", lastId.AsBsonMinKey);
var cursor = OpLogHandler.MongoCollection.FindAs<BsonDocument>(query)
.SetFlags(QueryFlags.TailableCursor | QueryFlags.AwaitData | QueryFlags.NoCursorTimeout)
.SetSortOrder(SortBy.Ascending("$natural"));
using (var enumerator = cursor.GetEnumerator())
@ashutoshraina
ashutoshraina / RequiredKeyAdapterFactory.java
Last active June 2, 2016 13:28
RequiredKeyAdapterFactory.java
public class RequiredKeyAdapterFactory implements TypeAdapterFactory {
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type){
final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
return new TypeAdapter<T>() {
@Override
public void write(JsonWriter out, T value) throws IOException {
if (value != null) {
@ashutoshraina
ashutoshraina / justify_text.go
Created October 25, 2020 01:56 — forked from CyrusJavan/justify_text.go
Justify Text - techincal interview question and answer written in Golang with many comments explaing the answer.
package main
import (
"fmt"
"strings"
)
func main() {
text := "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras " +
"venenatis, quam et dapibus porttitor, nisi mauris maximus sapien, a " +