Skip to content

Instantly share code, notes, and snippets.

View gatesvp's full-sized avatar

Gaëtan Perrault gatesvp

View GitHub Profile
@gatesvp
gatesvp / DnsLite.cs
Created June 7, 2017 21:18
Lookup MX records in C#
/**
@author Jaimon Mathew
csc /target:library /out:DnsLib.dll /D:DEBUG=1 /debug+ DnsLite.cs
*/
using System;
using System.Net;
ipfs : 01:02:21.637 INFO  cmd/ipfs: IPFS_PATH C:\Users\gates/.ipfs <autogenerated>:28
At line:1 char:1
+ ipfs daemon --debug *> .\ipfs_fsync_error.log
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (01:02:21...nerated>:28:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
01:02:21.637 DEBUG  cmd/ipfs: looking for running daemon... <autogenerated>:22
01:02:21.637 DEBUG  cmd/ipfs: Calling pre-command hooks... <autogenerated>:22
@gatesvp
gatesvp / Get-FolderSizes.ps1
Created July 18, 2012 19:22
PowerShell Get-FolderSizes
### Sample usage: Get-FolderSizes "C:\data" | sort size -Descending | FT -AutoSize
function Get-FolderSizes([string] $StartFolder) {
$results = @();
$colItems = (Get-ChildItem $StartFolder | Measure-Object -property length -sum)
$res = New-Object PSObject | select Folder, Size;
$res.Folder = $startFolder;
$res.Size = [float]("{0:N2}" -f ($colItems.sum / 1MB));
@gatesvp
gatesvp / test.js
Created June 12, 2011 01:53
Pull with regex
MongoDB shell version: 1.8.1
connecting to: test
> db.test.insert({ _id:3, "items": [ 'appstore.com', 'engineapp.com', 'asp.ca' ] })
> db.test.find()
{ "_id" : 3, "items" : [ "appstore.com", "engineapp.com", "asp.ca" ] }
> db.test.update({}, {$pull : { items: {$regex: 'app' } } })
> db.test.find()
{ "_id" : 3, "items" : [ "asp.ca" ] }
@gatesvp
gatesvp / step01.php
Created May 17, 2011 23:43
PHP commands for basic MongoDB operations
<?php
try {
$mongo = new Mongo(); // default host:port
$db = $mongo->example;
$collection = $db->test;
$document = array('x' => 1);
$collection->insert($document);
print_r($document);
<?php
try{
### Step 1 & 2
$m = new Mongo('ec2-50-16-121-178.compute-1.amazonaws.com');
$db = $m->admin;
### Step 3
$res = $db->command(array('replSetGetStatus' => 1));
print_r($res);
@gatesvp
gatesvp / isset.php
Created May 10, 2011 00:09
Sample with isset
<?php
try{
$m = new Mongo('localhost');
$db = $m->abc;
$collection = $db->def;
$collection->drop();
// Insert test data
$collection->insert( array('A' => 1, 'B' => 4, 'C' => array("C1" => 'val', "C2" => 15) ) );
@gatesvp
gatesvp / sort_test.php
Created May 9, 2011 17:54
PHP test sorting on sub-document
<?php
try{
$m = new Mongo('localhost');
$db = $m->abc;
$collection = $db->def;
$collection->drop();
// Insert test data
$collection->insert( array('A' => 1, 'B' => 4, 'C' => array("C1" => 'val', "C2" => 15) ) );
@gatesvp
gatesvp / nulls.js
Created May 4, 2011 18:30
Test for nulls in MongoDB
> db.foo.insert( { x : 1, y : 1 } )
> db.foo.insert( { x : 2, y : "string" } )
> db.foo.insert( { x : 3, y : null } )
> db.foo.insert( { x : 4 } )
> db.foo.find()
{ "_id" : ObjectId("4dc1974612c677fc83b5629d"), "x" : 1, "y" : 1 }
{ "_id" : ObjectId("4dc1974c12c677fc83b5629e"), "x" : 2, "y" : "string" }
{ "_id" : ObjectId("4dc1975312c677fc83b5629f"), "x" : 3, "y" : null }
{ "_id" : ObjectId("4dc1975a12c677fc83b562a0"), "x" : 4 }
> db.foo.find( { "y" : null } )
@gatesvp
gatesvp / document_digging.js
Created May 3, 2011 00:16
Reaching into documents
var x = {
"_id" : ObjectId("4dbf16ecee3bbe4d22000003"),
"options" : {
"options" : [ { "price" : { "_type" : "decimal", "val" : 1000 }, "label" : "10" }
],
"categories" : [[ "WTF","11" ]]
}
}
db.deals_test.drop();