:::: MENU ::::


  • Jan 11 / 2016
  • 0

Increase display limit for a find in Mongo Shell

When doing a find request on a Shell Mongo, the display is automatically paginated and you’re getting this:

Type "it" for more

By default, the number of rows returned is 20. But this value can easily be changed by using this command:

DBQuery.shellBatchSize = 200;

You will now have 200 rows displayed per page.

  • Dec 24 / 2015
  • 0

Manage permissions on MySQL for remote users

MySQL has always been one of the most used database engine for websites. Its security is really important, isolating and managing access must be taken in consideration.

Hereafter are some commands to perform some checking and some updates.
I will consider those variables for my examples, but you should customize them with your own:

  • Show permissions for user myuser on server myfirewalleddomain.local :
    show grants for 'myuser'@'myfirewalleddomain.local';
  • Revoke all privileges on my_db for user myuser on server myfirewalleddomain.local :
    revoke ALL PRIVILEGES ON `my_db`.* FROM 'myuser'@'myfirewalleddomain.local';
  • Grant access for SELECT on my_db for user myuser on server myfirewalleddomain.local with a password:
    GRANT SELECT ON `my_db`.* TO 'myuser'@'myfirewalleddomain.local' IDENTIFIED BY 'mYsupErs3curePassw0Rd' WITH GRANT OPTION;
  • Grant all privileges on my_db for user myuser on server myfirewalleddomain.local with a password:
    GRANT ALL PRIVILEGES ON `my_db`.* TO 'myuser'@'myfirewalleddomain.local' IDENTIFIED BY 'mYsupErs3curePassw0Rd' WITH GRANT OPTION;

  • Nov 26 / 2015
  • 0

Gather/Aggregate results with MongoDB

Need to gather or aggregate some results with MongoDB? Easy!

You can use the group command over any collection to get a nice display of your results aggregated:

     key: { document: 1},
     cond: { },
     reduce: function( curr, result ) {
                 result.total += 1;
     initial: { total : 0 }

You will get something like:

		"document" : "my_first_document",
		"total" : 44124
		"document" : "my_second_example",
		"total" : 3503
		"document" : "still_another_one",
		"total" : 3928

Here you are!

  • Oct 29 / 2015
  • 0

How to install NodeJS from sources in a specific directory

First of all, you need to update repositories, and make sure you have all the needed packages ready and installed:

sudo apt-get update
sudo apt-get install build-essential openssl libssl-dev pkg-config 

Then, you can retrieve the sources from the official NodeJS website by downloading the “Source Code” (here, it’s version 5.0.0):

sudo mkdir /opt/node/
cd /opt/node/
sudo wget https://nodejs.org/dist/v5.0.0/node-v5.0.0.tar.gz

Once downloaded, you can extract it in /opt/ directory for example (where it has been downloaded):

cd /opt/node/
sudo tar -xzvf node-v5.0.0.tar.gz

You can now open the new directory to compile and install NodeJS from sources:

cd node-v5.0.0/
sudo ./configure
sudo make
sudo make install

Your binaries (npm, node, …) are now available in /opt/node/bin/ directory.

Later, if you need to upgrade NodeJS you just installed, you will only need to download the latest version inside the same directory, extract the content in there and perform same installation process.

  • Oct 09 / 2015
  • 0

AWS – Update massively metadata using boto (python) on multiple S3 objects

A simple script that allows you to update massively Content-Type for files on an S3 bucket.
This script is able to:

  • Browse recursively a bucket
  • Perform action only on files matching specific prefix
  • Auto-detect type of file depending on its extension

Obviously, you can add any extension you want to the function update_md to handle more if needed.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, re, sys
import boto
from boto.s3.connection import S3Connection
from boto.s3.key import Key

# Variables

# Function to update MetaData
def update_md(k):
    Update the metadata with an existing object.
    # Get extension
    ext = k.name.split('.')[-1]
    if ext in ['bmp','BMP']:
        metadata = {'Content-Type':'image/bmp'}
    elif ext in ['jpg','jpeg','JPG','JPEG']:
        metadata = {'Content-Type':'image/jpeg'}
    elif ext in ['gif','GIF']:
        metadata = {'Content-Type':'image/gif'}
    elif ext in ['png','PNG']:
        metadata = {'Content-Type':'image/png'}
    elif ext in ['pdf','PDF']:
        metadata = {'Content-Type':'application/pdf'}
    elif ext in ['txt','TXT']:
        metadata = {'Content-Type':'text/plain'}
    elif ext in ['zip','ZIP']:
        metadata = {'Content-Type':'application/zip'}
    # If not same type -- update
    if metadata['Content-Type'] != akey.content_type:
      akey.copy(AWS_BUCKET_NAME, k.name, metadata, preserve_acl=True)
    return k

# Main function
if __name__ == '__main__':
    # Connect to S3
    conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
    b = conn.get_bucket(AWS_BUCKET_NAME)

    # Select files to parse (prefix can be specified)
    rs = b.list(prefix="")

    # Browse files
    for k in rs:
        print k.name
        akey = b.get_key(k.name)
        # Print type before
        print "Before:",akey.content_type
            k = update_md(k)
            akey = b.get_key(k.name)
            print "After: ",akey.content_type
        except Exception,e:
            print "Content-Type not handled by this script"

    print "Script finished!"
  • Sep 30 / 2015
  • 0

Apache – Proxy some URLs to another server

In Apache, if you want to forward some requests matching a regex to another server, you can use the rule ProxyPassMatch.

Here is an example that is matching URL like:

  • /admin/anything
  • /list/any number/info
  • /manage/any number

and redirect it to https://my-hidden-domain.com:26000

ProxyPreserveHost On
ProxyRequests Off
ProxyPassMatch ^/(admin/.*@.*|list/[0-9]*/info|manage/[0-9]*)$ https://my-hidden-domain.com:26000/$1

You can then define any rule you want with multiple rules matching different regex.ègles que vous voulez avec différentes expressions régulières.

Question ? Contact