Code Chewing Guides

PAGE 1 OF 3
  • How to run a command inside a docker container

    If you've built and launched a docker image, you might be left wondering what's actually going on within the container? What does the file system look like? Does that package exist?

    Perhaps you want to check some configuration setting, or check to see if a module or particular service is enabled and running... well there's a way.

    Get the docker container id

    If you don't know the docker image name or container id, begin by listing the running docker containers:

    $ docker ps
    CONTAINER ID  IMAGE         COMMAND         CREATED         STATUS         PORTS                         NAMES
    7015544736d9  fa21f0188248  "docker-ph..."  11 seconds ago  Up 10 seconds  80/tcp, 0.0.0.0:443->443/tcp  codechewing
    
    Read more
  • Customise your modernizr build using npm

    Using the modernizr CLI, combined with some npm action, you can craft a custom modernizr bundle, serving a reduced download size for your users, by only including the specific feature detects you actually need.

    Setup modernizr bundle config

    Grab a copy of modernizr, via npm:

    npm i modernizr --save
    

    Create the following modernizr.json file:

    Read more
  • How to remove nginx version from HTTP header

    The default nginx installation includes its version number, as one of the HTTP response headers. For example, your HTTP response headers might reveal something like this:

    HTTP/1.1 200 OK
    Server: nginx/1.13.0
    Date: Thu, 18 May 2017 20:03:43 GMT
    Content-Type: text/html; charset=utf-8
    Content-Length: 7740
    Connection: keep-alive
    

    In this case, note the Server: nginx/1.13.0 header and value, exposing the version details of nginx.

    Update nginx config

    Open up the main nginx config file, probably located at /etc/nginx/nginx.conf. Locate the http section within this file, and add in the following directive:

    Read more
  • How to add gzip file compression on nginx

    Adding gzip file compression can speed up the response time for your website. As with many optimisations, it's not a silver bullet, as compressing files on the server consumes CPU effort. However, the download size of transferred files is reduced for your end users.

    This guide will show you how to setup gzip compression for the nginx server.

    Enable gzip compression

    Open up the main nginx config file, probably located at /etc/nginx/nginx.conf. Locate the http section within this file, and add in the following gzip directives & values:

    http {
        # ...
    
        gzip on;
        gzip_comp_level 4;
        gzip_types text/plain text/css application/javascript image/png;
    
        # ...
    }
    
    Read more
  • Add your own custom facebook share button to your website

    There are many third party solutions, that offer ways to quickly embed share menus and widgets into your website. Services such as AddThis, even go as far as providing you with analytics. But all this can be excessive (and may take a hit on your page performance), if all you really want is for users to be able to easily share your article on their chosen social media platform.

    We're basically going to do the facebook part of this:

    Share menu with Facebook button

    If you're interested in creating your own twitter sharer too, check out our twitter share article as well.

    Sample facebook share window

    Read more