Skip to content

Instantly share code, notes, and snippets.

@leommoore
leommoore / file_magic_numbers.md
Last active April 14, 2024 09:15
File Magic Numbers

File Magic Numbers

Magic numbers are the first bits of a file which uniquely identify the type of file. This makes programming easier because complicated file structures need not be searched in order to identify the file type.

For example, a jpeg file starts with ffd8 ffe0 0010 4a46 4946 0001 0101 0047 ......JFIF.....G ffd8 shows that it's a JPEG file, and ffe0 identify a JFIF type structure. There is an ascii encoding of "JFIF" which comes after a length code, but that is not necessary in order to identify the file. The first 4 bytes do that uniquely.

This gives an ongoing list of file-type magic numbers.

Image Files

@leommoore
leommoore / nginx_basics.md
Last active March 2, 2024 01:13
Nginx Basics

#Nginx Basics for Ubuntu

Please see http://wiki.nginx.org/Main for more information. See http://arstechnica.com/gadgets/2012/11/how-to-set-up-a-safe-and-secure-web-server/ for a tutorial on how to install Nginx.

##Installation To install, you can install the version which is in the standard Ubuntu repositories but it is normally quite old and will not have the latest security patches. The best way is to update the repositories first:

apt-get update
apt-get install python-software-properties

apt-get upgrade

@rtgibbons
rtgibbons / logger.js
Created November 7, 2013 13:51
Logger Library with winston
var app = require(process.cwd() + '/app');
var winston = require('winston');
var _ = require('lodash');
// Set up logger
var customColors = {
trace: 'white',
debug: 'green',
info: 'green',
warn: 'yellow',
@leommoore
leommoore / systemd_services.md
Last active July 13, 2023 14:51
Systemd Services 101

Check that your system supports systemd

pidof systemd
2733

If this return a number then your system supports systemd. Most Linux distributions in 2017 support systemd.

Check out the proceses currently running.

Since systemd starts the process then all processes will be children of systemd

@leommoore
leommoore / mongodb_ssl_with_letsencrypt.md
Last active August 16, 2022 17:35
MongoDB 3.2.x SSL with Letsencrypt

MongoDB 3.2.x SSL with Letsencrypt

Letsencrypt is an initative which aims to increase the use of encryption for websites. It basically allows people to apply for free certificates provided that they prove the they control the requested domain. We will look at the what is needed to secure your MongoDB installation. For more details on setting up a MongoDB server see MongoDB 3.2.x.

Set the hostname

We sould to set the hostname to match the name of the certificate we are going to optain.

sudo hostname mongo0.example.com

Then update the hostname file to set the server name permanently.

@leommoore
leommoore / mongodb_3.2.x.md
Last active August 16, 2022 17:35
Mongo 3.2.x

#MongoDB 3.2.x

##Install MongoDB To install MongoDB on ubuntu from precompiled version.

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1404-3.2.5.tgz
gzip -d mongodb-linux-x86_64-ubuntu1404-3.2.5.tgz
tar -xvf mongodb-linux-x86_64-ubuntu1404-3.2.5.tar

Then check put what is in the bin directory

@leommoore
leommoore / javascript_memoization.md
Last active August 1, 2022 08:26
JavaScript - Memoization

JavaScript - Memoization

Memoization is a programming technique which attempts to increase a function’s performance by caching its previously computed results. Because JavaScript objects behave like associative arrays, they are ideal candidates to act as caches. Each time a memoized function is called, its parameters are used to index the cache. If the data is present, then it can be returned, without executing the entire function. However, if the data is not cached, then the function is executed, and the result is added to the cache.

  • Memoization can potentially increase performance by caching the results of previous function calls.
  • Memoized functions store a cache which is indexed by their input arguments. If the arguments exist in the cache, then the - cached value is returned. Otherwise, the function is executed and the newly computed value is added to the cache.
  • Object arguments should be stringified before using as an index.
  • Memoization can be automatically applied to referentially transpa
@leommoore
leommoore / JavascriptCalculatingStandardDeviations.md
Last active May 25, 2022 11:19
Javascript - Calculating Standard Deviations

Javascript - Calculating Standard Deviations

This is based on a excellent post by Derick Bailey.

function standardDeviation(values){
  var avg = average(values);
  
 var squareDiffs = values.map(function(value){
@leommoore
leommoore / S3Cmd.md
Last active May 25, 2022 11:14
S3Cmd

S3Cmd - S3 Command Line Tools

S3cmd is a free command line tool and client for uploading, retrieving and managing data in Amazon S3 and other cloud storage service providers that use the S3 protocol, such as Google Cloud Storage or DreamHost DreamObjects. It is best suited for power users who are familiar with command line programs. It is also ideal for batch scripts and automated backup to S3, triggered from cron, etc.

S3cmd is written in Python. It's an open source project available under GNU Public License v2 (GPLv2) and is free for both commercial and private use. You will only have to pay Amazon for using their storage.

It is available on http://s3tools.org/s3cmd

Installing S3Cmd

@leommoore
leommoore / mongodb_3.2.x_replica_sets_on_aws_ec2.md
Last active March 15, 2022 22:28
MongoDB 3.2.x Replica Sets on AWS EC2

#MongoDB 3.2.x Replica Sets on AWS EC2 A MongoDB replica set provides a mechanism to allow for a reliable database services. The basic replica set consists of three servers, a primary, a secondary and an arbitrator. The primary and secondary both hold a copy of the data. The arbitrator is normally a low spec server which just monitors the other servers and help with the failover process. In production, there can be more than three servers.

To setup mongo as a replica set on Amazon Web Services EC2 you need to first setup a security group with ssh on port 22 and mongodb on port 27017. You then need to create three servers. Select Ubuntu 14.04 LTS x64 and a micro (or bigger depending on your database size, ideally you should have enough memory to match your database size) instance for the primary and secondary and a nano instance for the arbitrator.

##Adjust the File System on each Server The operating system by default will update the last access time on a file. In a high data throughput database application