Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env coffee

# Add document

mongo = require 'mongodb'

server = new mongo.Server "127.0.0.1", 27018, {}

client = new mongo.Db 'test', server
@lancelakey
lancelakey / gist:5682906
Last active December 17, 2015 22:38
MongoDB implicit collection creation strikes again!

"MongoDB will create collections and databases implicitly upon their first use: you do not need to create the database or collection before inserting data."

Look closely at Fri May 31 03:10:53.198 through Fri May 31 03:10:55.837 All of that work being done, time being spent, those 2+ seconds, is MongoDB performing initial setup creating the collection required to store the first document I'm adding to that collection.

So: Although "you do not need to create the database or collection before inserting data" you do need to expect that the very first document you add will include a few seconds of setup time.

# mongod run --port 27018 --quiet --nojournal --dbpath environments/test/data/mongo
Fri May 31 03:10:24.292 [initandlisten] MongoDB starting : pid=6313 port=27018 dbpath=environments/test/data/mongo 64-bit host=ip-10-172-51-100
@lancelakey
lancelakey / gist:5225768
Created March 23, 2013 00:28
Ruby Vs. CoffeeScript: Battle #1
Ruby Total: 17
~ > pry
[4] pry(main)> def add(a,b)
[4] pry(main)* a+b
[4] pry(main)* end
=> nil
[5] pry(main)> add(1,1)
=> 2
#!/usr/bin/env bash
set -x
ps axfu | grep -iE 'ruby|java|node|redis|mongo|cassandra'
/etc/init.d/redis-server stop
/etc/init.d/mongodb stop
/etc/init.d/cassandra stop
rm -rf /var/lib/cassandra/*
@lancelakey
lancelakey / install_cassandra.sh
Created October 5, 2012 07:46
Debian install Cassandra 1.1.x
#!/usr/bin/env bash
# Target OS: Debian
# Install Cassandra 1.1.x
sh -c 'echo deb http://www.apache.org/dist/cassandra/debian 11x main >> /etc/apt/sources.list.d/cassandra-stable.list'
sh -c 'echo deb-src http://www.apache.org/dist/cassandra/debian 11x main >> /etc/apt/sources.list.d/cassandra-stable.list'
gpg --keyserver keyserver.ubuntu.com --recv-keys 4BD736A82B5C1B00
gpg --export --armor 4BD736A82B5C1B00 | apt-key add -
@lancelakey
lancelakey / install_rbenv.sh
Created October 4, 2012 08:55
Debian install rbenv, ruby-build, ruby
#!/usr/bin/env bash
# Target OS: Debian
# Install rbenv, ruby-build, ruby
# Update, upgrade and install development tools:
apt-get -qy update
apt-get -qy upgrade
apt-get -qy install build-essential git-core curl libssl-dev \
libreadline5 libreadline5-dev \
@lancelakey
lancelakey / ruby_puts_version.rb
Created October 3, 2012 22:30
Ruby put ruby version and loadpath
#!/usr/bin/env ruby
puts RUBY_VERSION
# puts the ruby load path
puts $:
Object.constants.sort.each {|c| cv=Object.const_get(c); print c, "=", cv, "\n" unless Module === cv}
@lancelakey
lancelakey / install_mongodb-10gen.sh
Created September 28, 2012 02:57
Install MongoDB onto Debian from 10gen Repository
#!/usr/bin/env bash
# Add 10gen Debian repository to apt sources
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo -e "\n# 10gen\ndeb http://downloads-distro.mongodb.org/repo/debian-sysvinit\tdist 10gen" >> /etc/apt/sources.list
apt-get update -y
# Install misc packages
apt-get install -y vim tmux psmisc
@lancelakey
lancelakey / create_ruby_debian_package.sh
Created September 16, 2012 01:40
Create Ruby 1.9.3-rc1 Debian package using FPM
#!/usr/bin/env bash
# On a new / clean installation of debian squeeze
# Install Ruby from source
# Create a Debian package using FPM
# Update apt
apt-get update -y
[14] pry(main)> cd a
[15] pry(#<Fog::Compute::AWS::Server>):1> ls
Fog::Attributes::InstanceMethods#methods: _dump attributes dup identity identity= merge_attributes new_record? requires requires_one
Fog::Model#methods: collection collection= connection connection= inspect reload symbolize_keys to_json wait_for
Fog::Compute::Server#methods: scp scp_download scp_upload ssh ssh_port sshable?
Fog::Compute::AWS::Server#methods: addresses ami_launch_index ami_launch_index= architecture architecture= availability_zone availability_zone= block_device_mapping block_device_mapping= client_token client_token= console_output created_at created_at= destroy dns_name dns_name= flavor flavor= flavor_id flavor_id= groups groups= iam_instance_profile iam_instance_profile= iam_instance_profile_arn= iam_instance_profile_name= id id= image_id image_id= instance_initiated_shutdown_behavior instance_initiated_shutdown_behavior= ip_address kernel_id kernel_id= key_name key_na