Skip to content

Instantly share code, notes, and snippets.

@leommoore
leommoore / node_testing_mocha.markdown
Last active October 4, 2015 08:08
Node - Mocha Testing
@leommoore
leommoore / node_memcached_basics.md
Last active October 13, 2015 04:58
Node - Memcached Basics

#Node - Memcached Basics

Memcached is an in memory key-value store.

Installing Memcached

apt-get install memcached

To check the version

@leommoore
leommoore / node_error_handling.md
Last active December 11, 2015 01:38
Node - Error Handling

#Node - Error Handling

##Uncaught Errors

var http = require('http');

http.createServer(function() {
  throw new Error('This will be uncaught');
}).listen(3000);
@leommoore
leommoore / javascript_regular_expressions.md
Last active December 12, 2015 02:48
JavaScript - Regular Expressions

#JavaScript - Regular Expressions (Regex)

Regular expressions are a language for describing patterns in string data. It is available in many languages including JavaScript.

Regular expressions are denoted by slashed (/) instead of quotes. ie /Hello/. Also Regular expressions are objects in JavaScript and have a number of methods including test which returns true or false if the pattern is found.

###Search Search return the index of the start of the text (like IndexOf), if it is found. Remember, the first location (ie h) is 0. An result of -1 indicates that the Regex was not found.

@leommoore
leommoore / linux_log_file_monitoring.md
Last active December 17, 2015 11:39
Linux - Log File Monitoring

#Linux - Log File Monitoring

Logwatch is a really useful tool which normally runs as a cron job which mails a summary of the log files to root. It shows a summary of software installed, repeated authentication failures from programs such as sshd and su.

For example running:

logwatch --detail med --range Today --format text --output stdout
@leommoore
leommoore / javascript_observer_pattern.md
Last active December 24, 2015 05:59
JavaScript - Observer Pattern

#JavaScript - Observer Pattern An array of subscribers are just callback functions

  • addSubscriber() and removeSubscriber() methods that add to and remove from the subscribers array
  • A publish() method that takes data and calls all subscribers, passing the data to them
  • A make() method that takes any object and turns it into a publisher by adding all of the above methods to it
var observer = {
@leommoore
leommoore / linux_partitions.md
Last active February 1, 2016 19:24
Linux Partitions

#Linux Partitions The best time to partition is when you are doing a fresh install.

  1. In Ubuntu, when you are prompted to erase the disk, select 'Something Else' and click 'Continue'. You will see a single device /dev/sda.
  2. Click the 'New Partition Table..' button. Read the warning and click 'Continue'
  3. Select the free space and click on the '+' button next to Change to create a partition.
  4. Main System Partition - Can be as little as 15-20Gb or larger if necessary. Choose the Gb figure and multiply by 1024 and enter the figure in the size box. Leave 'Primary','Beginning of this space' and 'Ext4 journaling file system'. Select '/' under the mount point and click 'OK'
  5. Select the remaining space and click '+' again. Click on the 'Use as' dropdown menu and select 'swap area'. Set the partition type as Logical, but set its location as 'End of this space'. The size should be approximately the same as the memory or at least 1Gb. Choose a figure and multiply by 1024 to get the Mb figure
@leommoore
leommoore / ubuntu_installing_java.md
Last active August 10, 2016 21:07
Ubuntu - Installing Java

#Ubuntu - Installing Java

##Java 8 sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer

##To install the JDK

sudo apt-get install python-software-properties

@leommoore
leommoore / mongodb_javascript.md
Last active October 28, 2016 02:03
MongoDB - JavaScript

#MongoDB - JavaScript Since a query may return a large number of records which is too large for the client, the find returns a cursor instead of the data. This cursor can be assigned to a variable.

var vendorCursor = db.vendors.find();

You can see the size of the cursor using:

vendorCursor.size();

You can check to see if there is more data after the current cursor point in the data set using:

@leommoore
leommoore / node_installing_node.md
Last active February 20, 2017 09:31
Installing and Compiling Node.js

#Node - Installing and Compiling Node.js

##Simple Install Ubuntu

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

##Compile and Install