This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is the base directory where all user will be segregated (like: "chroot") | |
BASE_DIR = new File(System.properties.baseDir ?: "/tmp").canonicalPath; | |
// This map maintains the session state for every connection. | |
// for this telnet server the state will be limited to the current directory | |
_connections = [:]; | |
// Connection id counter | |
_cids = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// general configuration | |
settings = [port: 1234]; | |
// Vert.x server and event-bus | |
def server = vertx.createNetServer() | |
def bus = vertx.eventBus | |
// Connection handler. Here requests are captured, parsed, and executed. | |
server.connectHandler { sock -> | |
// upon a new connection, assigning a new connection id (cid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regular expression to verify/extract pathnames from commands | |
PATH_ELEM = "[A-Za-z0-9.-]+" | |
PATH = "(/?$PATH_ELEM(/$PATH_ELEM)*/?|/)" | |
// Commands handler | |
bus.registerHandler("commands") { | |
msg -> | |
def cmd = msg.body.command | |
switch (cmd) { | |
case ~$/cd( $PATH)?/$: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////////////////////////////////////// cd | |
def cd(def path, String cid) { | |
path = path == "" ? null : path | |
def newPath = virtual2real(path, cid); | |
if (!newPath.exists() || !newPath.isDirectory()) | |
return [status: "ERROR", message: "### ERROR: $path: no such directory!".toString()] | |
// changing directory | |
_connections[cid].curDir = new File(newPath.canonicalPath); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is the replica set name | |
# every node will need to have the same name | |
replSet = setname | |
# this is the authetication encryption key | |
# this will be required to be same on every node | |
keyFile = /etc/mongodb.key | |
# This is the operational log size | |
# here we assume ~24GB for example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate the key and make it readable only by mongo server | |
sudo openssl rand -base64 753 > /etc/mongodb.key | |
sudo chown mongod:mongod /etc/mongodb.key | |
sudo chmod 0600 /etc/mongodb.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd /var/lib/mongo/local | |
# as root user | |
for i in {0..11} | |
do | |
echo "Initializing new-local.$i" | |
dd if=/dev/zero of=new-local.$i bs=2146435072 count=1 | |
chown mongod:mongod new-local.$i | |
chmod 0600 new-local.$i | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stopping the server | |
sudo /etc/init.d/mongod stop | |
# now replace local.n files | |
cd /var/lib/mongo/local | |
sudo rm -fr local.* | |
sudo rename 's/new-local/local/g' new-local.* | |
# restarting the server | |
sudo /etc/init.d/mongod start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* this benchmark compares the speed of | |
* the reminder operator vs the bitwise | |
* equivalent. | |
*/ | |
public class ReminderBenchmark { | |
final static long d = 8; | |
final static long mask = d-1; | |
final static long REPEAT = 1_000_000L; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn crypto-square [s] | |
(->> (re-seq #"\w+" s) | |
(map clojure.string/lower-case) | |
(apply str) | |
(#(let [size (int (Math/ceil (Math/sqrt (count %))))] | |
(partition size size (repeat " ") %))) | |
(apply map vector) | |
(map (partial apply str)) | |
(clojure.string/join "\n"))) |
OlderNewer