Skip to content

Instantly share code, notes, and snippets.

View ofirski's full-sized avatar

Ofir Kerker ofirski

View GitHub Profile
@ofirski
ofirski / LongAsTimeUUIDTypeCodec.java
Created December 6, 2019 15:41
TypeCodec for mapping java.lang.Long values to Cassandra's TimeUUID using DataStax Java Connector
package ofirski;
import com.datastax.oss.driver.api.core.ProtocolVersion;
import com.datastax.oss.driver.api.core.type.DataType;
import com.datastax.oss.driver.api.core.type.DataTypes;
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
import com.datastax.oss.driver.api.core.type.reflect.GenericType;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import com.datastax.oss.driver.api.core.uuid.Uuids;

Keybase proof

I hereby claim:

  • I am ofirski on github.
  • I am ofirski (https://keybase.io/ofirski) on keybase.
  • I have a public key ASAIOkXWguEjJZfL7c3orqtd4xUs8kZ5STmH9dxGIIxcnQo

To claim this, I am signing this object:

@ofirski
ofirski / create_deploy_user.sh
Created October 1, 2017 09:30
Create deploy user as sudo
sudo useradd --create-home -s /bin/bash deploy
sudo adduser deploy sudo
sudo passwd deploy
@ofirski
ofirski / merge_mongo_collections.js
Last active March 15, 2017 13:32
Merge MongoDB collections
/*******************************************************************************
* Merges matching documents from source collection into desination collection
* Usage:
* mergeCollections("srcCollName", "destCollName", null, ["f1","f3"])
* mergeCollections("srcCollName", "destCollName", {xy:"z"}, ["f1","f4"])
********************************************************************************/
function mergeCollections(sourceCollection, destCollection, sourceQuery, setFields) {
var nMatched = 0;
var nModified = 0;
sourceQuery = sourceQuery || {}
@ofirski
ofirski / find_one_by_id.js
Last active September 15, 2016 20:36
Add findOneById to MongoShell's DB collection
/****************************************************************************
* Add this snippet to ~/.mongorc in order to load it to any shell initiated
* Usage:
* db.myCollection.findOneById("5149cdbb62d5cbb22c000024")
* db.myCollection.findOneById("5149cdbb62d5cbb22c000024",{"field":1})
*****************************************************************************/
DBCollection.prototype.findOneById = function(objId ,fields, options ){
return this.findOne({"_id":ObjectId(objId)}, fields, options);
}
@ofirski
ofirski / redis-server
Created February 20, 2014 16:38
init.d script for redis-server
#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db