Skip to content

Instantly share code, notes, and snippets.

View gatesvp's full-sized avatar

Gaëtan Perrault gatesvp

View GitHub Profile
@gatesvp
gatesvp / Node Install
Created October 23, 2010 05:48
Just a quick series of lines to install node.js, assuming a basically blank Linux install
# Apt-get basic build and git
sudo apt-get install build-essential
sudo apt-get git-core
# Set up a folder for Node.js, then download and build
mkdir node_src
cd node_src
git clone git://github.com/ry/node.git # may take a few minutes
cd node
./configure
use cookie;
/**
* Cookie to lookups process
*/
create_new_lookup = function(x) {
var ins = new Array;
var outs = new Array;
for(var i in x.maps) {
@gatesvp
gatesvp / MediaShoutExport.ps1
Created November 20, 2010 20:30
Copy all files for a given MediaShout presentation (along with the presentation) into a single folder. Update the presentation to use the locally referenced files, this way the presentation is actually self-contained.
# Select-FileDialog Function #
# Created by Hugo Peeters #
# http://www.peetersonline.nl #
###############################
# Note: store in your profile for easy use
# Example use:
# $file = Select-FileDialog -Title "Select a file" -Directory "D:\scripts" -Filter "Powershell Scripts|(*.ps1)"
function Select-FileDialog
// Get a the current collection size.
var storage = db.foo.storageSize();
var total = db.foo.totalSize();
print('Storage Size: ' + tojson(storage));
print('TotalSize: ' + tojson(total));
print('-----------------------');
print('Running db.repairDatabase()');
@gatesvp
gatesvp / nested_docs.js
Created January 27, 2011 08:28
An example of using nested docs. Or basically a hash table instead of an array of js objects.
var x = {_id: 1, 'tags' : { 'castle' : { 'n' : 10 }, 'age' : { 'n' : 2 } } };
var y = {_id: 2, 'tags' : { 'keep' : { 'n' : 2 }, 'castle' : { 'n' : 6 } } };
var z = {_id: 3, 'tags' : { 'keep' : { 'n' : 5 }, 'cats' : { 'n' : 6 } } };
db.doc.save(x);
db.doc.save(y);
db.doc.save(z);
// find all docs
db.doc.find();
@gatesvp
gatesvp / powershell_startup.ps1
Created February 16, 2011 00:00
easy powershell aliases
function df {
$colItems = Get-wmiObject -class "Win32_LogicalDisk" -namespace "root\CIMV2" `
-computername localhost
foreach ($objItem in $colItems) {
write $objItem.DeviceID $objItem.Description $objItem.FileSystem `
($objItem.Size / 1GB).ToString("f3") ($objItem.FreeSpace / 1GB).ToString("f3")
}
@gatesvp
gatesvp / subset.js
Created February 16, 2011 18:26
Proper subset function for MongoDB $where clause
// Define function
subset = function (test, superset) {
if (test.length > superset.length) {
return false;
}
for (var i in test) {
found = false;
for (var j in superset) {
found = found || superset[j] == test[i];
}
@gatesvp
gatesvp / $set example
Created March 3, 2011 17:46
Create a new data field using set
> var d = {
... drives:{
... C:{
... windows:{
... 'explorer':{
... admin:'r+w'
... }
... }
... }
... }
Method One: Array of Objects
------
var pd = { type: "Person", attributes: [{name: "Penelope Doe"},{age: 26}] };
var pd2 = { type: "Person", attributes: [ {name: "Johnny Doe"},{age: 27} ] };
db.foo.drop();
db.foo.save(pd);
db.foo.save(pd2);
db.foo.ensureIndex({attributes:1})
db.foo.find({'attributes' : {age : {$gt : 26 } } }).count()
db.foo.find({'attributes' : {age : {$gt : 26 } } }).explain()
print(' ')
printShardingStatus()
db.runCommand({enablesharding : 'fred_sharded'})
db.runCommand({enablesharding : 'fred_sharded2'})
db.runCommand({shardcollection : 'fred_sharded.temp', key:{'_id':1}})
db.runCommand({shardcollection : 'fred_sharded2.temp', key:{'_id':1}})
db2 = db.getSisterDB('fred_sharded')
db3 = db.getSisterDB('fred_sharded2')