My blog of Technology, Javascript, CSS, Databases, Mongo, Docker, TDD, Blockchain, Data structures, and anything else I'm into

HTTPS Certbot

Make sure you have setup and secured your server first. sudo apt install certbot python3-certbot-nginx sudo certbot --nginx -d some domain.com Accept the option to rewrite all calls to https. sudo systemctl reload nginx Check the status of auto renew: sudo systemctl status certbot.timer Dry run a renewal: sudo certbot renew --dry-run ...

Dynamic Host in Swagger

This was a little bit of a nightmare, keeping a reference handy ...

Tao Te Ching

I'm going to annotate the Tao Te Ching, putting it into my understanding of its meaning. Chapter 1 The tao that can be described is not the eternal tao The name that can be spoken is not the eternal name The nameless is the boundary of Heaven and Earth The named is the mother of creation If ...

Art and Code Aesthetics

Why do I struggle with GoLang? I mean it should be simple right? Yet coding in it didn't quite fit my mental framing. I struggled with understanding this then I realised - I like beautiful code. I've been doing js for a long time now. I got into functional programming, 'declarative' paradigms etc. The ...

Monitoring Purposeful Productivity

Agile and other means were created to solve the problem of 'how to deliver a project', and create a product or service. From the sheer number of these systems extant we can probably guess that nobody knows how to consistently build a product or service without failure. There are a shit-tonne of ways a ...

VS Code auto update bug

For some reason I was getting errors with VS Code auto updating. This fixed it ...

Getting Tezos set up

To get a Tezos network up and running I found the only way was to use Docker. The installation was riddled with bugs (probably due to an OSX update I did). Anyway, follow the 'how to get' instructions [https://tezos.gitlab.io/introduction/howtoget.html] and follow the first section - Docker images. If you want to give it a ...

The Near Protocol

The Near Protocol [https://nearprotocol.com/] is a sharded proof of stake public blockchain. Its emphasis is to be developer friendly making it easier to build, onboard, and scale mainstream commercial DApps. Near uses AssemblyScript [https://docs.assemblyscript.org/] (a strict subset of Typescript) or you can use Rust [https://docs.nearprotocol.com/docs/near-bindgen/near-bindgen]. You can use the studio [https://studio.nearprotocol.com/] to ...

Creating A Udemy Course

So I went ahead and created my first Udemy course on Test Driven Development using Javascript and Jest [https://bit.ly/32QttAL]. I really enjoyed it. I created the Game of Life (see the working example [https://digioli.co.uk/game-of-life/]). The course was more like a prototype, or experiment for me - how to create a course. I learned a ...

Impressum/Imprint/Tcs And Cs

This website and all of its content is free to use. All content is created and used from my own personal investigation and/or projects. Digioli Ltd is my registered company I use for freelance work, the only connection between the content and my services are the name 'digioli'. Due to my detestation of general ...

Learning Rust

One of the first things I like to do after gaining some familiarity with a language is a couple of katas, maybe Blackjack, an API of some sort. All test driven of course. Thats what we'll do here. Check out my rust repo [https://github.com/roppa/learning-rust]. Definitions Rust is a (system language)[ https://en.wikipedia.org/wiki/System_programming_language], meaning it can be used for ...

Digital Signature With OpenSSL

Digital Signatures are used in an agreements, authorisations, contracts, and obviously a huge part of blockchain and crypto. Here is an example of creating an agreement, signing, and verifying using OpenSSL [https://www.openssl.org/]. Lets create a document, which needs an agreement (signature): echo I, Bob, promise to pay Mark £1000 by 1/1/2020 > contract.txt For this ...

Intelligence, Artificial Intelligence, Learning, Consciousness

Artificial Intelligence is all the buzz lately. I remember Back at University I did a module on neural networks, quite a few labs, and was especially interested in Expert Systems. I remember at the time writing essays on AI, even getting down to Homunculus arguments. However, the year 2000 was not right for ...

Money, Capitalism, and Entrepreneurship

I have just been hit with something. Smacked in the face really. It never ceases to amaze me how much in the dark I am (and probably most people). I have just looked at the dictionary definitions of 'Capitalist' and 'Capitalism'. However, not all dictionaries are created equally. Before jumping in, we need ...

Developer Frustrations

Years ago when we did websites for people, it would go something like this: Them: 'Hey! I need a website' Me: 'Ok, cool, what content do you have?' Them: 'I dunno, can you make something up?' Things haven't changed much. Agile Lets keep things dynamic so we don't have to plan anything, or code anything that we ...

Docker Volumes - Persisting Data

In my case I had a large amount of files to be used in a 'downloads' directory for Nginx. Ieally I wanted these files to be in a container. This is where Docker Volumes comes in. # create an empty volume docker volume create myvolume # create a temporary container and mount the volume docker container ...

Baleen

Installation download or clone [https://github.com/dstl/baleen] from github. Also read the getting started/wiki [https://github.com/dstl/baleen/wiki/Getting-Started]. First I installed maven using homebrew (brew install maven). Then navigate to the baleen directory and build using: mvn package After a time, and if everything is OK, a target directory will be created, containing a jar file. To run baleen: ![Screen-Shot-2019-04-06-at-15.23.52](/content/images/2019/04/Screen-Shot-2019-04-06-at-15.23.52.png) Pipelines ...

Triangles and Circles

Are you a Triangle or a Circle? Ok, pretty abstract I know. Reality Reality needs to be covered first as both circles and triangles depend on it. Reality is defined as 'the state of things as they actually exist, as opposed to an idealistic or notional idea of them'. Wow, what a definition. No ...

Cypress.io E2E Tests

Jest is great and all that, but wow! check out Cypress.io [https://www.cypress.io/]! Thats it for me, e2e more than unit tests. Check out the docs [https://docs.cypress.io/guides]. This great video too [https://www.youtube.com/watch?v=5XQOK0v_YRE]. ...

Scripting Setting Up A New Machine

I like automating boring stuff. When setting up a new machine I tend to run a script that does a lot of the grunt work for me ...

Big Endian and Little Endian

Remember Gulliver's Travels? The two cities that were fighting each other were called the Big Endians and the Little Endians - fighting because they couldn't agree which end of the egg should be cut when eating soft boiled eggs. Typical. However, beware, the end is not the end, it is the beginning. The ...

VSCode keybindings.json

Place your key bindings in the keybindings.json file to overwrite the defaults: [ { "key": "cmd+k", "command": "workbench.action.terminal.clear", "when": "terminalFocus" } ] ...

Standard.js

I know how linting makes your code so much nicer, but I'm not sure how many hours of my life have been wasted in the past through discussions about semi-colons, how many spaces ad nauseum. Step in Standard.js [https://standardjs.com/]. First I removed all my existing eslint and dependency modules (including Airbnb, about 4 of them). Then ...

Right, Wrong & Right And Wrong

There is being right, and there is being right. There is being wrong, and there is being wrong. There are differences. Right and Right You can be right. I hope you are. If you are right, you are empowered, responsible, and in control. To me this is a pleasant state, and dare I say 'neutral'. ...

One Reason To Still Use Gulp

I believe that every tool has its particular use. There are fashions, styles, trends, bias (especially with developers), etc, but you have to have the right tool for the job. Let me get this straight - I usually only use npm scripts. However, I have been given a repo with just front end ...

Linkerd

Definitions Service mesh the mesh provides service discovery, load balancing, encryption, authentication and authorisation, support for the circuit breaker pattern, and other capabilitiesThis was a proof of concept, to see how easy it was to use. Check out the example [https://github.com/roppa/linkerd-example]. The steps I took to test this were: * Create a Go server docker ...

Internationalisation - I18n With React-Intl

I{['nternationalisatio'].length}n or I18n or 'Internationalisation'. Look no 'zee'; we're British. First, install 'react-intl'. import { IntlProvider, FormattedMessage, addLocaleData } from 'react-intl' import App from '../App' import en from 'react-intl/locale-data/en' import zh from 'react-intl/locale-data/zh' import messagesEn from '../../locales/en.json' import messagesZh from '../../locales/zh.json' const messages = { en: messagesEn, zh: messagesZh } addLocaleData([...en, ...zh]) const languageRegion = (navigator.languages && navigator.languages[0]) || ...

Configuring SSH

To stop having to log in each time with ssh there are some things you can do. Vi/vim ~/.ssh/config and add: Host * UseKeychain yes Or you can be more specific: host 20.30.40.* user myuser identityfile ~/.ssh/custom_id To add to your keychain: ssh-add -K ~/.ssh/custom_id The -K means when adding identities, each ...

Fixing Bluetooth Speaker Stuttering on Mac

Just one of the many little annoyances that interrupt the flow. Kind of like setting up https and renewing certs. Anyhoo, Mac lets you tweak the quality of audio output over bluetooth. The trailing int at the end of the command below is that number: defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" -int 53 References ...

Creating Your Own Javascript Testing Framework

Testing is essential to development. I've obviously used testing libraries such as Mocha, Chai, Ava, Tape, etc. But how would you go about writing one yourself? How would you build a test framework using that same framework to test itself? I got to thinking, just what would a test runner or 'test harness' ...

Mongodb Docker Backup

There are a few ways to back up data in mongo. For now I just want to use mongodump. I decided to create a shell script with something similar to: docker exec mydatabase mongodump -o /data/db/backup -u root -p password -d mydatabase --authenticationDatabase admin --host localhost:27017 --gzip Then cmod +x the file, and ...

Blockchain, Bitcoin, And Cryptocurrency

Introduction If totally new to the subject, I wrote some notes about blockchain in general [/simple-blockchain-primer/] with some definitions etc. What is a Blockchain? A simple definition is 'a distributed ledger'. A ledger is a collection of financial accounts. Distributed means the exact copy exists in multiple places. But what does this mean? How ...

Setting VS Code Terminal to ZShell

I couldn't find how to set the default terminal to zshell online. Here's how I did it: Code -> Preferences -> Settings Search for 'Terminal'. Set "terminal.integrated.shell.osx" to "terminal.integrated.shell.osx": "zsh" Voila. ...

GoLang

A lot of teams are at least investigating GoLang. I love Node but started learning GoLang because the last place I worked had some apps written with it. I also started learning out of curiosity. I created a github repo with some examples [https://github.com/roppa/learning-go]. Learning GoLang You usually have to start with a hello world ...

Simple Blockchain Primer

Basic Definitions: Economics the branch of knowledge concerned with the production, consumption (use of, disposal, decrease, exhaustion etc), and transfer of wealth (energy potential) Ledger a book of financial accounts. Also a flat stone covering a grave. Comes from Old Dutch meaning a ‘large bible’ Distributed given a share of something to each ...

Securing MongoDB With Docker Compose

I had a little bit of an issue authenticating with docker compose. To add an admin user with docker compose you use the provided environments: MONGO_INITDB_ROOT_USERNAME, MONGO_INITDB_ROOT_PASSWORD, and MONGO_INITDB_ROOT_PASSWORD. version: '3.3' services: example-db: image: mongo restart: always container_name: example-db environment: ...

Bitcoin Development

I wanted to learn a bit more about Bitcoin development so I created a hello world example. First, generate an address and get some bitcoins. Then check your balance to make sure it has been mined ...

Recording iPad/iPhone screen on a Mac

When you have to demo an iPad/iPhone app you can use QuickTime player. 1. Connect your iPhone/iPad 2. On your Mac, open QuickTime player 3. File > New Screen Recording 4. In the recording options, select device 5. Record ...

Carbon Design React Components

IBM have created Carbon Design System [http://www.carbondesignsystem.com/] for their Cloud products. The team describe the system as 'a collection of reusable HTML and SCSS partials to build websites and user interfaces'. So it is similar to other boilerplate frameworks. Benefits As mentioned, they have reusable components, both HTML and SCSS. They have decent support for accessibility ...

Securing Your Ubuntu Server

Used a great digital ocean resource on securing an Ubuntu server. Condensed the steps into a script ...

Watch and Run Tests

I used to put a script in each package.json file called dev. The idea was to watch for changes and then run tests. No need to pollute the scripts section because we can abstract it to a system wide command. First thing to do is npm install -g watch. Then add an alias ...

Advanced Markdown tips

Blatant copy of the default Ghost article :-) If you've gotten pretty comfortable with all the basics of writing in Ghost, then you may enjoy some more advanced tips about the types of things you can do with Markdown! pecial formatting As well as bold and italics, you can also use some other ...

Functional Programming in Javascript

I started work on an FP library in order to learn this paradigm. I called it funcker [https://github.com/roppa/funcker] - 'func' in functional, plus getting your head around fp can be a bit of a 'funcker'. Functional programming is one of the original paradigms of computing. Then things moved more towards a physical ...

Circle.ci

Circle.ci [https://circleci.com] is the best CI tool I have seen so far. Super easy to get started. It is more similar to TravisCI then others (Jenkins, Drone.io). I signed up with my GitHub account and it automatically provides a list of your GitHub projects in the 'Add Projects' menu. Just select the project ...

Converting an IPFS Hash to 32 Bytes

What is an IPFS hash anyway? Take for example, ‘hello world’. When we add it to IPFS it generates this hash: Qmf412jQZiuVUtdgnB36FXFX7xg5V6KEbSJ4dpQuhkLyfD Breeeaak it down one time. [Qm] - two bytes Q is the function code, the m is the digest length (e.g the length of the rest of the hash). This is called ...

A DAG Example in Javascript

One thing I've learned is to really understand something you have to do it. More times going over something = certainty. So if you forget the deets of something you read two weeks ago, thats totally understandable. Use it or loose it. Anyway I digress. This is a series of data strucutures, working up ...

Solidity Function Overload

Solidity does not support optional parameters, but what it does support is method overrides. Just like in Java you can declare a function multiple times as long as the arity and/or types are different. Example I tried on remix: pragma solidity ^0.4.18; contract Overload { function calculate (uint _a, uint _b) public pure returns ...

Publishing an NPM Module on IPFS

I recently published a npm module of mine called wordify [https://www.npmjs.com/package/wordify] on the IPFS network. First things first, follow the getting started guide [https://ipfs.io/docs/getting-started/]. Then run the daemon with ipfs daemon. For ease, we will install stay-cli [https://www.npmjs.com/package/stay-cli] globally: npm install -g stay-cli In your repo folder, run stay init. This will update your ...

Koa.js Basics

I've recently started using Koa [http://koajs.com/]. I'm a big fan of Express but have heard good things about Koa so thought I would take a look at it. I've created an example api [https://github.com/roppa/koa-api] as I like to learn by doing. At first glance it is very similar to Express through the use ...

React with Mobx

I never really got into the Redux stuff. At first glance it looked a bit convoluted; I was into other things so didn't get into it. Plus apps I was working on were far from complicated. Overkill to a degree. I do like a bit of FRP though, and think observables are really ...

Creating and Deploying a React Native App to iOs and Android

Starting consists of installing Create React Native App [https://github.com/react-community/create-react-native-app] globally using yarn global add create-react-native-app. Install Watchman next. We will be developing with Expo.io [https://expo.io/] too, advice from the React people. On your testing devices install from the AppStore [https://itunes.apple.com/us/app/expo-client/id982107779?mt=8] or GooglePlay [https://play.google.com/store/apps/details?id=host.exp.exponent]. I recommend using VSCode as a development environment - lots ...

Cryptography and Security Primer

Definitions Cryptography From the Greek meaning 'hidden writing' Cipher A secret or disguised way of writing something Code A system of symbols or words used to represent other meanings. Sometimes used for the purposes of secrecy Encryption Turning communicable information into gibberish. Comes from latin meaning 'hidden' Decryption Turning gibberish into meaning Ciphers ...

Blockchains and Distributed Ledger

This is the first of many brain dumps of Crypto technologies. Definitions Ledger A book of financial accounts Distributed Shared amongst a number of recipients Cryptography The art of writing or solving secret codes Immutable Not changing or unable to change over time DL Distributed Ledger where data is structured ...

Yarn git+ssh Package Installation, ssh and ~/.ssh/config

I've been including some private repos in some work I've been doing recently and Yarn has been spitting its dummy out at packages that begin with 'git+ssh'. The fix locally was to create an ~/.ssh/config file using vim ~/.ssh/config. If the file is not there it will create one. Then add host information ...

Hyperledger and Other Distributed Ledger Technologies

These are just some notes I made when I was using Hyperledger. Definitions Peer A peer is a single 'entity' in the network. It is a machine that shares a portion of their resources to other network participants without a central coordinator. Peers all maintain the state of the ledger, and have a copy ...

Logging to Graylog from Node using Bunyan

The source code for this is on Github [https://github.com/roppa/bunyan-graylog-node]. Also read the Graylog docker installation docs [http://docs.graylog.org/en/2.3/pages/installation/docker.html] first. Graylog has dependencies on Mongo and Elasticsearch which I didn't know. Elasticsearch is cool. Build the node image with: docker build -t bunyan-node . Then run docker compose up build. Testing the endpoint using http is easy: curl -XPOST http://localhost:12201/gelf -p0 ...

YAML

YAML ain't markup language. But it is. YAML [http://yaml.org/] is a 'data serialisation standard', or basically a way to convert your data into a text format that can be converted back while maintaining integrity. It's technically a superset of JSON, which means you can use JSON syntax within it. Check out the spec ...

IPFS

Interplanetary filing system is a decentralised filing system. It is a mashup of several things. Think of it like a torrent network, where you download a file using peers. Done over a Tor network. Content can have multiple versions too, so you can think of it like git. Just like a torrent, you ...

Data, Logic, Sanity, and Reasoning

I've had a few discussions with friends recently about 'Fake news' and what can be done about it. This is a deep deep question with many ramifications. Especially when you are dealing with humans. Here I'm endeavouring to delineate some of my aquired knowledge on the subject of logic, reasoning, sanity, fact, and opinions. As ...

Learning and Staying on Top

What did you do that for? So what is your purpose for learning? What do you want to get out of it? This could be broken down to each study session you have - you should have a purpose. Otherwise you could go on and on flipping through pages and pages in some ...

Validating Objects with Joi

I was working on a contract recently where there was a lot of JSON objects passed around from api to api. We investigated lots of validation methods for this type of thing. Simple key value || null sufficed for the simpler objects, however when object values were nested it got a bit tricky. ...

Ethereum and Solidity Smart Contracts

Definitions Turing-Complete theoretically capable of expressing all tasks accomplishable by computers - sequences, selections, and iterations Addresses 20 byte values. Every account and smart contract on the Ethereum blockchain has an address and can send and receive Ether to and from this address Wallet An application that contains public and private keys Transaction ...

SSL With Letsencrypt And Nginx

Lets face it, setting up SSL can be a beyatch. Apart from setting up locally [https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec] , then it is really easy (comparatively). Definitions SSLSecure sockets layer - a protocol which encrypts data so it is only decrypt-able between the sessions client and server. If you intercept any of the packets they will look like jumbled ...

Functional Programming in Javascript

This is my little foray into the world of functional programming. I mean, I was sold when Curry was mentioned. See the source code [https://github.com/roppa/funcker]. Functional programming is one of the original paradigms of computing. Then things moved more towards a physical representation of the world - Object Oriented. Like the circle of life, we ...

Nginx and Docker Service Discovery

In a traditional and simple scenario, your app setup would have a box for your web server, a box for your api, a box for your database. Each would have a static IP addresses so you know how things would be connected. Life in a cloud is different. Because it is a cloud ...

Keycloak

Keycloak is an open source and easy way (it boasts 'no code') Identity and Access Management. It works with 'single sign on' (SSO) too, which is the main reason I am investigating it. For SSO users authenticate with keycloak and it handles things from there, so no login forms and validation code. It can ...

Make and Makefiles

This is an awesome intro to make, so start there. Make is a utility to maintain groups of programs. Essentially, as programs got quite large, where there were lots of include files, complex steps in building, compiling, and where one change resulted in the whole program being compiled, make came to the rescue. It would ...

LDAP and Active Directory

Well if you're reading this then you must have some task to do using active directory. I feel for you. Thats why I'm here too. LDAP stands for Lightweight Directory Access Protocol. Directory access comes from telephone standards that were converted to digital equivalents in the 1980s. LDAP is a protocol to search over ...

Javascript Interview Questions

Nobody knows Javascript 100%. Nobody. I've met haughty people who pretend they do, but they don't. I also sometimes find interviews a little invalidating, like maaan you caught me out on a total edge case. Or sometimes, when I've been conkers deep in Elasticsearch or CSS or some other seemingly random task I ...

Node.js with NTLM

I know, why? Well sometimes as an engineer you have to clean the toilet. * NT - (Windows) New Technology * LAN - Local Area Network * NTLM - is Windows authentication protocol running on an NT LAN. In a Windows network, NT LAN Manager (NTLM) is a suite of Microsoft ...

Learning Python

One word, learnpythonthehardway [http://learnpythonthehardway.org/]. ...

Atom snippets

It is super simple to add your own snippets to Atom. You can either create them as a json file, or the default cson format. The snippets file is located in your home directory in the .atom folder: vim ~/.atom/snippets.cson I was sick of typing use strict, module.exports, describe, and it ...

DOM Event Delegation

DOM event delegation is simply letting a parent element look after his/her kids, leaving the kids alone to play. So instead of adding an event to each of the children, we add an event to the parent element. Adding event listeners willy-nilly pollutes the DOM, is not easy to manage i.e. you can ...

Debugging Node

I've just setup node inspector [https://github.com/node-inspector/node-inspector] for debugging. I created basic a test app [https://github.com/roppa/node-debug] based on the documentation on nodejitsu.com [https://docs.nodejitsu.com/articles/getting-started/how-to-debug-nodejs-applications] . I've written an overview here too. Install node inspector [https://github.com/node-inspector/node-inspector] globally: npm install node-inspector -g Run your app in debug mode using the --debug flag: node --debug index.js Run the inspector in a new ...

NPM and Node Modules Offline

This is assuming we are using a *nix based OS. Scenario We have a secure system that has no outside world connection, nothing, nada, zilch. Getting code on/off is done using a flash drive. (insert crying emoticon here). Problem We need to get our node app into the system and able to run npm script commands making ...

BASH

Bish bosh bash. Why do lots of boring tasks when they could be automated? Bash something out instead. Why? A lot of Linux scripts are written in Bash, and an understanding of it helps in other areas, such as piping (|) and outputting (>) in npm scripts. How? Using the built in commands as covered in ...

Fun with Node.js and Arduino

Get yourself an Arduino or Espruino. Do it. Then get started with the nodebot workshop [https://www.npmjs.com/package/nodebot-workshop]. And then find a Nodebots [http://nodebots.io/] meetup near you. Install nodebot workshop globally: npm i -g nodebot-workshop Then start doing some tuts with Johnny Five [http://johnny-five.io/], Nodeschool [http://nodeschool.io/] and node-ardx [http://node-ardx.org/]. I bought a few kits from Amazon ...

Mac Keys

Aaaahhh, for yee to cast the magick spell yee have to know the symbols and their meaning, aaaahhh! Symbols have mass and meaning. Mass, cos they exist in the physical realm. Meaning, because it is a substitute for the real thing, a pointer even. * ^ The caret symbol is the 'ctrl' (control) ...

Angular 2

Angular 2 [https://angular.io] is written in TypeScript [http://www.typescriptlang.org/], which is a superset of ES6. This means ES6 will work in TypeScript, but TypeScript has a lot of extra cool features such as types and annotations. Annotations from Java are the ability to add meta data to classes, methods, variables et al. They are ...

Nginx

These are some notes I made when working on a customisable Nginx [https://github.com/roppa/custom-nginx] (also I made some other examples [https://github.com/roppa/nginx-examples]). Nginx is many things, a super fast web server, a streaming server, a reverse proxy, load balancer, cache, and probably a lot more. Whats good about it? * Configuration is intuitive (based on ...

Elasticsearch

Elasticsearch is described as a 'full text search' and 'analytics engine'. A glossary is a good thing to peruse first, a couple of definitions are given below, to get a grip of the nomenclature. Full text Containing the full text, as distinguished from meta data like a database with an author field, title, date ...

Tree Package for Mac

I was going through a Neo4j tutorial and the guy ran a tree command to get a tree structure of a directory. Really nice. It isn't standard on a Mac, but is on Ubuntu. I installed it through homebrew: brew install tree Super easy. Now, to run all you need to do is ...

Docker

It's called Docker for a reason. Imagine all the worlds goods being transported from country to country as-is. What a nightmare. Instead lets create a standard container, known dimensions, structure etc, then we can put what we want inside, and then transport it as a single unit. Wow. Docker enables us to package an ...

IBM Watson

If you haven't done much with IBM Watson I highly recommend taking a look at it. I first really experienced it at the TechCrunch hackathon in London (2015). We got free use of IBM Bluemix and some credits for Watson. The SDK is so well written it was so easy to implement. Watson is ...

Sublime Text Build Script

I like using npm scripts [/2015/11/01/using-npm-build-tool/] to watch any changes to files and 'livereload'. Sometimes I code directly in Chrome's console. Another thing I sometimes do is use Sublime's build script 'Tools > Build' or 'cmd + b'. To enable this, go to 'Tools > Build System > New Build System' and enter ...

Node Streams

'Aaahh be like water', Bruce Lee said, 'be like water'. Streams flow and you manage them with piping, just like plumbing. source.pipe(destination) So to take input from the terminal (stdin), and redirect it out (stdout) we would do something like this: process.stdin.pipe(process.stdout) So whatever character you type, you see it duplicated. In node all streams are instances ...

Mathematics, Algebra, Algorithms and Cool Animations

This article will be the root of all following articles. The purpose is to convey in painfully simple terms Mathematic concepts, algorithms, so that they can be used in things such as cool animations. Definitions root the places wheres something begins. Origin algorithm a set of steps to do in order to achieve ...

JavaScript Interview Questions

Try/Catch/Finally I had an interview a while back and one of the questions was to do with try/finally. Given this function: function test () { try { return("hello") } finally { console.log("finally"); } } What gets output from the below? console.log(test()); The answer is actually: > finally > hello How come? Because the ...

Semantic Versioning 1.0.0

This is the first version of this article and hopefully it will not be changed later. But that is something that cannot be guaranteed. So you are building your API, service, or App. We have Alpha, Beta, Live, yeah, but how do these relate to semantic versioning? Versioning is important. Semantic versioning refers to ...

About me

I have been passionate about programming since my first computer course instructor, Colin Patrick Brown, showed me how to convert numbers to binary. He then showed me hexadecimal, and octal. Mind. Blown. That course covered JSP, SSADM, Flow Schemas, COBOL, a smidgeon of C. Such a great course. That was just before the ...

Using NPM as a Build Tool

NPM isn't just a package management tool, it is much more than that. You've probably seen the "scripts" attribute of the "package.json" file and noticed you can add your run and test directives there. You can do a lot more than just "run" and "test". I've used Grunt (mainly) and Gulp build tools, but ...

Functional Reactive Programming

Most of this is my notes from Jafar Husain's FRP course (he is an awesome teacher). "Functional Reactive Programming" sounded like some more buzz words to me when I first heard it from the awesome Timothy Quach [http://webfoundry.io/]. I was wrong. Functional Reactive is a different programming paradigm. Things like Facebook's React have used the words ...

Client Storage Notes

Just some notes on client storage. Cookies Text. Sent with each request. localStorage persistent to a small maximum, something like 5MB. Local storage keeps things stored 'forever'. Good for username fields, preferences for website display or something like that. ...

Lexical Scope

It has been said that there are two types of developer, the Wizard and the Scribe. Myself, I think I fall somewhere in between. The Scribe in me needs to know the definitions of words used, and also the context. Sometimes, especially when the pressure is on, I just do something that works ...

Google APIs

This is more of an Alan Partridge style 'note to self' thing, like 'Monkey Tennis'. I was perusing the tinterwebs and was looking over Google's APIs and came across some interesting ones I'd like to consume: ...

ES6 - ECMAScript 6

es6fiddle.net [http://www.es6fiddle.net/] is a great resource to try things out in a browser. Check out the comtability tables [http://kangax.github.io/compat-table/es6/] too. Tail Call Doing recursive calls in Javascript eats up the memory as each call is added onto the call stack. Asymptotically it is O(n). That is because Javascript is not a proper tail recursive ...

Put a Sock in it. HTTP Sockets

socket - one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to. An endpoint is a combination of an IP address and a ...

Using Heroku and Node

Lets create an app from the command line [https://devcenter.heroku.com/articles/creating-apps]. heroku create roppa Thats it. Next though we need to create a git repo and push it to heroku. Lets start with git [https://devcenter.heroku.com/articles/git]: git init git add . git commit -m "Initial commit" Next we need to create a heroku remote. heroku create Lets confirm everything is up on ...

Learning resources

There are tonnes of resources you can use to sharpen your skills or learn new stuff. Some of the ones I'm using now, or have recently used are listed below. Polyglottal * Substack [https://github.com/substack/training] wizardly training * Hired in tech [http://www.hiredintech.com/app/] * Learn x in y minutes [https://learnxinyminutes.com/] * Codewars [http://www.codewars.com/] ...

Embedding JavaScript

Scripts (without any async or deferred attributes) are fetched and executed immediately before the browser finishes parsing the page. It basically waits for the file to be downloaded and executed before progressing. Async and deffered are boolean html5 attributes which get around the above bottleneck. With async and deferred scripts start downloading immediately and the ...

Interacting with the DOM

The DOM is a convention used for interacting with HTML elements - a platform independent model, meaning it is up to the vendor to implement it. HTML nodes are in a tree format, so using JavaScript it is possible to create, update, delete HTML elements. It is a combination of an API ...

JavaScript Bitwise Operators

Binary is cool. For me, learning binary was the "WOW" moment that got me hooked on programming. That moment I could see how HDDs worked, and how the whole machines were just running like clockwork. Anyhoo, so we have these bits, and we can do things with them, efficiently. Lets imagine today was brought ...

React.js

In the beginning I was using functions that interacted with the DOM - time consuming and messy. Then we had libraries like jQuery, MooTools, Yahoo etc, equally messy. Then we had MV* such as Backbone, pretty cool. However, not really great for complex apps. Same for Angular, better to begin with, but full of ...

Multiple jQuery Ajax Promises

If you're using jQuery and are doing multiple ajax calls - on a recent project there was a pyramid of doom loading in lots of templates. A cool technique to avoid this is to roll the ajax calls into a single promise. The $.when method can take multiple promises so we can ...

The JavaScript Number Type

Like most things in JavaScript, mysteries are wrapped in enigmas. Just kidding. But it is true that some things are not how they appear. I had an interview once at a stinky bank (what was I thinking?). One of the technical questions was something along the lines of "does 2.031 === (1.001 + 1.03) ...

HTTP Response Codes

HTTP is the bread and butter of developers, but who wants to remember tonnes of response codes? When trying to remember these codes I get a lot of 404s from my brain; so I'm listing them out for my future self. Hashtag #futureself. I got these originally from Marty Hall's great JSP and ...

Base64 - what, why, and how

When you have anything that varies, and you want to have a standard agreement, then you have to have some sort of a convention. This is the case with encoding data. Things like email are sent as ASCII and can't handle binary data, so the binary data needs to be converted into text. ASCII [https://en.wikipedia.org/wiki/ASCII] ...

Publishing to NPM

A while ago I was playing with some code to do with words. I know most code involves some sort of words, or symbols at least, but mine was literally to do with words. Word counts, getting the list of words in a text, chunking words so you could create a reading app, ...

Using Your NPM Module/Library in Node.js or a Browser

You can easily use your library in Node.js and client side (aka Isomorphic). All that is needed is a couple of conditional statements and an encapsulating IIFE. (function (root) { }(this)); The IIFE calls itself using this [/2015/06/17/this/] to reference the global context. Client side "this" will reference "window". In Node.s it will reference the ...

Developer Tools

I have a massive tool. In fact I have lots of them. That just sounds wrong. Anyway, I'm going to list ones I've found handy. Local CSS Dev. Edit and persist changes to your code using Devtools workspace ...

Templating

So you want to use a template library and there are sooo many out there. Simply use this template chooser [http://garann.github.io/template-chooser/]. ...

Test Your Javascript Knowledge

I think tests should be fun. It should be about feedback regarding where you are and how to get to where you want to be. It should be used in order to help EVERYONE get 100%. Tests should not be about categorisation, invalidation, nervousness and trauma. I know, a little heavy :-) So ...

Node Process Managers

When I first used Node.js, for the first hour of development I was like ctrl+c, npm start, ctrl+c,npm start ... what a nightmare. Fortunately there are some nice people out there who "made it so". So we don't get RSI. Any time some file changes in our node directory the server is ...

CSS Flexbox

Let's be honest, CSS float layouts were a nightmare. Absolute and relative positioned things we won't say anything about. And display: table just feels really dirty. I mean really dirty. Especially when you started out using tables for layouts (I even felt dirty doing that, even though others felt it was ...

A Glossary of Sorts

I have a curious mind. Whenever there is a term, symbol or phrase I haven't seen before I get an immediate "?" in my head. I think a lot of people take for granted words and phrases, use them with the "everybody knows" attitude. A pet hate of mine. I believe that any ...

Lean UX

I bought and watched the Lean UX video course from O'Reilly a while back. TOTALLY AMAZING! Well, that might be a little over the top, but I have been in the US a while now. But yeah, this is a really great course. Highly recommended ...

Learning VIM

Vim is a popular command line text editor available by default on most Unix/Linux Systems. If you do any SSH server admin, knowing the commands for one of these editors (or those like it) is essential. Otherwise it is a bit of a nightmare. I would totally suggest doing this first. Just type vimtutor ...

Grunt

Grunt [http://gruntjs.com/] is a task runner. A virtual assistant as it were. It is there to make your life easier, doing all of the "grunt" work. However, this assistant speaks its own language, so in order to get the assistant to assist, we have to speak in the language it understands. Ok, so ...

REST Brief Intro

REST is an acronym for 'Representational State Transfer'. Yo, Represent. This meaning 'depict' or 'stand for'. State, as in the condition of the thing represented. And transfer meaning to pass from one point to another. It is a protocol, meaning it uses existing technology in a format understood by both client and server. URI and ...

JavaScript and Number Systems

With JavaScript it is easy to interchange number systems (binary, decimal, hexadecimal, octal, et al). We can do so by using the "toString" method. If you pass in the radix you want to convert into, the result will be a number of that radix. I don't think there is a way to charge ...

Mac Path Variables

Ok, I admit it. I was a Microsoft user for a number of years. Phew, it feels so good to let that out. It wasn't all bad however. Microsoft keyboard shortcuts are much better than Mac. So was changing PATH and environment variables. When I first had to do it on a ...

Mongo.db

Basic commands First install Mongodb, there are lots of ways to do this. I used Homebrew but I know some people suggest against it. To get your mongo server (daemon) running, run:nmongod. To shutdown the service, run: ...

NPM

npm is bundled with node. It is best to make sure you have the latest version. You can use an interactive package.json creator when creating a node module. For more information on the below visit getting started with semantic versioning. To use latest patches use ...

Authentication Salt And Hash

Authentication is verifying you are who you say you are. Authorisation is letting you do only what you are allowed to do. HTTP is stateless, that is how it was designed. However I wouldn't like to have to enter a username and password on every page of every website though, that would be sooo ...

JSON P

That sounds like a rapper. It's not though, the p stands for padding. Sometimes the "p" has been interpreted to mean "prefix". Padding? Padding is the term used because the requested JSON data is "wrapped" in a function. A bit of foundation first though. What happens if you load data from somewhere using AJAX is that ...

Data Structures in JavaScript

Data structures are a cornerstone of software engineering. I have come to really appreciate these. I mean, that is what we actually deal with - data, structured data, information. To visualise any of the structures below I would go to Visualgo.net or Object playground. People don't queue in London so this ...

Multiple versions of Node

If you want to install Node it's best to use a utility that allows you to run specific Node versions. The most straightforward one is called "n". npm install -g n n stable Override the node installed by brew using: n stable Uninstall the version of node you installed with brew so that only the n ...

Javascript Testing

Testing is essential to development. I've obviously used testing libraries such as Mocha, Chai, Ava, Tape, etc. But how would you go about writing one yourself? Especially how would you build a test framework using that same framework to test itself? I got to thinking, just what would a test runner or 'test ...

Node module.exports and exports

Node gives us a shorthand variable reference called "exports", which references "module.exports". "exports" is just a reference to "module.exports". exports === module.exports. What is this module.exports anyway? Under the hood, something like the below happens behind the scene when we create a module ...

JavaScript Event System

Lets say we are super rich and we have an butler who handles things for us. In fact, we live so leisurely that any mundane events are taken care of by our secretary/personal assistant. That would be nice. It is the same thing in JavaScript. We don't want to take care of everything ...

Logarithms and Big O Notation

My mathematical education was somewhat lacking as at school I was put in the "divvy" classes - classes for the "not too bright" or "remedial". So coming across terms like "logarithm" is a little unsettling. I'm assuming that some people reading this may not be familiar with the term either, so I will endeavour ...

Making Git less of a Git

Sick of me using the Googles for commands I don't use all the time but want to keep track of. Ah why does commit message open in [vim, nano] Easy to change, even open in VS Code etc. I prefer vim. Also I don't like doing -m, writing in an editor with the ...

Closures

A closure is a function object that has a reference to the variables in the context it was created in. var increment = (function () { var i = 0; return function () { return ++i; } }()); Within the IIFE we have set i to 0. ...

D3 basics

We did a hackathon at work and wanted to do some geographical data visualisation so D3 is the first choice. I mean, that is the name of it D * 3 = Data Driven Documents. I've had limited experience of D3 so I thought it would be a nice foray to it. The first ...

Pseudo Classical Inheritance

Lets face it JavaScript inheritance patterns are a bit mind boggling. Especially pseudo classical inheritance. So lets start at the top and get a couple of things straight. * Objects are collections of name/value pairs * Objects are create from the Object constructor * Objects have a hidden "link" to another object, ...

Algorithms and Big O

Oh. Big oh. Or rather Big-O. I thought "O" stood for "operations". And "big" because of magnitude. Man I was way off: In the family of Bachmann-Landau notations, the one most relevant to algorithms was the one with the Omicron symbol. That symbol can be best described textually or verbally as a 'big O'. ...

Bind

All tied up with Bind? I know the feeling - fifty shades of it. It took me a while to understand what is going on with Bind. Reading the documentation a few times still left me wondering what was going on. The bind() method creates a new function that, when called, ...

JavaScript Inheritance Patterns

JavaScript a very slippery Object Oriented language. Functions are actually objects. A total paradigm shift from other languages like Java and PHP. There are many ways to "create objects", some are more economical and efficient than others, while some seem very complex. Functional We can set up a function that acts like a constructor function, ...

Apache Solr

Solr Basics Solr is an open source search tool written in Java and based on the Apache Lucene Library. It is meant to be a stand alone web application. It exposes REST like endpoints which can also be extended on (you can set up your own endpoints). Solr can also be embedded in software. Solr is ...

Arrays

Your boss might twitch a bit when you mention arrays ("a raise", get it?). I strongly suggest using Mozilla developer docs for JavaScript reference materials. Sometimes technical writers have a penchant for obfuscation though, so I've just noted down some Array methods that have some finer points ...

Terminal Velocity

I admit it. I was a Microsoft user for a long time. In the DOS days I did my fair share of command line business. I then got suckered into the crutches of window based things. To get really fast and efficient, command line mastery is essential. I would first start with learning ...

Amazon EC2 and Continuous Deployment using Bamboo

So you want to start integrating your shizzle on a continuous basis? Bamboo is great tool for that - especially if you use any other Atlassian toolset such as Jira and BitBucket. You can download and install a bamboo server locally, or another option is to run it on the cloud using an "Elastic ...

This

Yeah that. Well sometimes you can set a variable to refer to "this" as "that", but "that" is another story. When I was a Java programmer, it was easy to understand what "this" was. It was "this", a built in reference to the thing instantiated. Simple. Getting up to scratch with Javascript means understanding ...