Work and insights from Crowdhailer at Workshop 14. I focus on developing lightweight solutions to modern standards. This blog will cover best practices, efficient work-flow and other items of interest
I am moving to a new blog as part of developing my company to deliver software. There are already a few articles up and more in the pipeline. There will be lots of goodness on software topics as well as the latest projects I am working on.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
Yesterday I published I post that I wrote a year ago and never got round to again. When I started learning to code I hope to keep a list of the key pieces of the tech jigsaw as I came across them and explain them to other people who wanted to learn. I think this would still be a good Idea as even a non programmer can gain a lot by knowing a few things about the internet.
I however never got round to completing this series of posts and find myself wanting to write about other things. I did keep the list of things and there is so much excellent information online I have decided just to summarize the topic
So I was ruminating away on what it is to be intelligent how we judge something to be conscious. I was doing this because it seams that we may soon if not already have enough computing power to model a human brain. (That is if we don't already). Even if we are not there yet Moors law still seams to be active and there is nothing stopping us running the simulation slower than realtime. i.e. 1 day of computer work gives us 1 hour of brain behaviour. This may one day allow us to answer my first question.
Is consciousness an emergence phenomenon?
My reasoning is if a computer can simulate a consciousness then it emerged from the 1's and 0's dancing to their simple rules. However if with computers 10, 1000, 1000000 times more powerful than now if an artificial intelligence cannot reproduce conscious thought then we would have to conclude that we are fundamentally different from the processing power we have. Not just because we have emotions, our super super computer would be able to model the chemical soup with think in perfect well. Note there is no cut off point where we can prove that consciousness is NOT emergent but with each failed attempt we gain evidence to that point. I think it is very likely in my life time we will have strong confidence on the answer and wonder what this might mean for us. Admittedly we will probably just carry on because hardly anyone read the paper and the media misrepresented.
Next up.
So how can we tell if a computer is intelligent?
The Turing test says that a computer is intelligent when it can fool a person into believing it is human. Ready for a segway? what is sleep for, it must be fundamental to managing a biological intelligence. Why? because if not it would have been evolved out. Sleeping is not a good survival tactic. So my test for intelligence is as follows.
A machine is intelligent when, without prompting, it asks for a nap.
That's all. There was in fact one more note I had made and it sounds interesting.
Systems need no knowledge of designer. Game of Life
When I started programming I found that the logic of simple programming came easily. The logic behind loops and their ilk was clear. What caused me much greater difficulty was conceptually putting all the pieces of the computer and internet puzzle together. I often found that example code was not helpful but chatting with someone in the know was. At this point I have to thank my college from last year as he put up with the lions share of questioning. What I needed was concise information on the standards that are used. This post is much of the useful information I have discovered. It is ordered roughly as I came to understand them myself. I hope this can speed up readers understanding of the puzzles I struggled with.
To start at the vey beginning what is the internet and what is the web and are they the same thing? The answer is they are not, the internet is the network of computers all across the globe that are connected together. The web is short for the world wide web and is all of the pages you can see on the internet. Therefore the internet can happily exist with out the web, but the web has to live on the internet.
To illustrate the difference are two example applications that use the internet but not the web. Firstly sending email is not done using webpages, for people familiar with outlook your emails are separate from any webpage. To add confusion you can now read your emails on webpages. Googlemail is an example of this. Secondly apps with live data, such as one showing bus departure times. The live data has to be requested from a source and this is done over the internet but not using a web page.
The world wide web is the linked collection of webpages available on the internet. To understand the web it is now necessary to understand a webpage. A webpage is hypertext file(html) and a universal resource locator(url). A hypertext file is nothing more special than any other type of file. It contains rules that are useful to it use. in the same way that a word file has rules that make it good to store documents and a jpeg file rules to store images. The rules for reading a hypertext file are ones that make it good to save text with link.
a url is the address for a webpage within the web.
To view webpages you need a browser. The browser is a program that fulfils two key functions. First it asks the internet it is connected to send it pages from the web that it requests. Secondly it builds the webpage as you see it from the data in the hypertext file that is returned.
The web browser you use is likely to be one of this list
Internet Explorer
Mozilla Firefox
Opera
Chrome
Safari
When you type a webpage address into the bar of your browser then it sends out request to be sent the hypertext file (web page) at that url(address). It does this using a standard method across which is know as hypertext transfer protocol(http). It does exactly what it says on the tin this is the protocol (method) to transfer hypertext files. In this instance from it address to your browser.
Note: other types of file may be transferred using http such as images.
At this point we can understand what information is in the top bar of your browser.
http://www.crowdhailer.tumblr.com/
This is instruction to the browser to use the http instruction set to fetch from the world wide web the page located at peterhsaxton.tumblr.com
How the internet finds and returns a given page is not in the remit of this blog mostly as it is only something I have very recently worked out and you can gain much understanding before addressing these details.
The returned file will be an hypertext markup language (html) file. Hypertext denoting that the file contains links and a markup language is a system on annotating a document which is distinguishable from the text of the document. Simple html has tags to denote sections of text as paragraphs, titles or lists as well as well as the inclusion of elements such as horizontal lines and images
An html file does not contain images it actually contains links to images of the web wich the browser has to fetch and add to the page. It is in this way that the browser is responsible for building webpages that you see. There are good reasons for this separation
Reused images can be downloaded only once
A small HTML file contains all the "content" needed to understand the page.
The html page can also contain links to two other interesting types of file. A CSS file and a JavaScript (JS) file. The CSS file contains styling information about how to display the content in the HTML file. The JS file contains instructions on how a webpage should behave.
In conclusion HTML/CSS/JS are the ingredients of a full webpage. They are delivered over the wires of the internet to be build on your computer by your browser.
A quick disclaimer: I no longer use grunt. I have changed to gulp because I prefer its code over configuration approach. However I think grunt still has great value for someone who wants the advantages of automation without all the details of JavaScript.
This is not an introduction to grunt, that is very well explained on the official site. Grunt is a task runner for JavaScript. That sounds very simple, you can use grunt to do tasks for you, however isn't all programming running prescribed tasks or programs. I would say yes and so what is the use of grunt?
Grunt is nothing but a neat way to package tasks which are added as plugins. Essentially grunt has no value without the plugins that its community has generated. With these grunt is wonderful.
So with that here is a whirlwind intro to some of the grunt tasks I have made use of.
Concatenation contrib-concat
With this plugin you can automatically gather JavaScript/CSS saved in several locations and combine them to one file. This is best practise for performance by reducing HTTP request and speeding page load time.
Minification contrib-uglify, css-min
There are plugins to minify JS, CSS and HTML. This decreases the sizes of assets by removing comments, white space and several other things that human readers find very useful. This reduced size of files to be served is also helpful in speeding up a page load time.
Watch contrib-watch
Automate the automated tasks, this task watches for changes to files, upon which it will run other grunt tasks. Save any changes in your js files and a new minified version will be ready almost instantaneously
Linting jslint
Existing for JavaScript and CSS these task will check the quality of code you are writing, The value of jslint at catching mistakes is really huge.
Some More interesting task
The above are a powerful toolkit on there own, this next selection are more for the curious
load-grunt-tasks
Efficiency or Laziness, whichever it is, it becomes contagious once grunt is running. This task saves you from having to individually add every grunt plugin to your grunt file. And will instead load every node package that is prefixed with 'grunt-'
time-grunt
This will record the time that each task takes to run. If a task is build of several tasks it will tell you the percentage time on each. So far this is more interesting than useful. It might provide early warning if you are minifying lots of images that you have too many as the time creeps up.
grunt-newer
This task provides can prefix any other task and will only run that task again if the files it is acting upon have changed since the last time the task was run. A useful way of speeding things up.
localtunnel-me
Not a grunt task but a great addition to the development workflow. Previously I was pushing a version of my project to heroku to show it to other people. This meant that my project was littered with commits such as 'test this new thing on phone'. Now this is all replaced with localtunnel. Grunt has several plugins that allow you to spin up a server with your project. with local tunnel you can take a locally running server and with no knowledge of how make it available the world over with one command
$ lt --port 8000
your local server port 800 will be made available at 'random.localtunnel.me' A really great service
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
Webcomponents, Functional Reactive Programming, and Microservices
The title of this post mentions three area that have been interesting me over the last few months. They are three very different technologies but all have a similar goal. I believe that they are all aiming to increase the expressiveness of the code you write by making it say more about what you are doing and less about implementation. In essence they all tackle this in different domains. It may be argued that to some level many patterns and trends in programming exist to increase expressiveness.
So this post could grow to an epic if I tried to discuss all three in detail. So I will just give a quick overview. No opinions but needless to say I am excited by all of them.
Web Components
This is a conglomeration of emergent specifications that will allow pages to be divided more along the lines of widgets/sections. This is instead of separation into just three functional pieces namely content(HTML), style(CSS) and behaviour(JavaScript). The four new web standards for web components are
Custom Elements
HTML Imports
Templates
Shadow DOM
Browser support is variable and progress can be checked here. They can be experimented with now using a polyfill library called polymer. A decent introduction can be found here.
Functional Reactive Programming (FRP)
I first came across this in the excellent JavaScript library bacon.js. There are other implementations such as rx.js. FRP is a structure to handle events and data manipulation. It aims to provide a consistent language for manipulating event stream that have much in common with collection operations such as map, reduce and filer. The analogue being that a stream of clicks can be considered an array in time of click. How helpful that visualisation is I am unsure off but the code is definitely a wonderful step up the abstraction ladder. To have an overview I would definitely recommend this walk through of implementing snake
Microservices
Fundamentally this is about breaking up a well organised large application into several smaller applications that run in concert to create on application agglomeration to a user. There are several benefits to this approach, each can be written in the language most suitable to its task, they can easily be rewritten when the business environment changes. The downsides are mostly the added complexity with deploying many services but this can be mitigated with automation and making use of services such as heroku. An excellent introduction is here.
Single Responsibility
The Single Responsibility Principle (SRP) is a cornerstone of good code design but there is more to it that the simplicity of its statement gives away. It took me a while to discover what I see as a key feature of single responsibility and that is a concept of scale.
In a restaurant the chef has the single responsibility to prepare food while the waiter has the single responsibility to deliver food. However into this mix we can add a tin opener that has the single responsibility to open tins. These are however not three equal partners. It is evident that the chef can use the tin opener without having two responsibilities, namely preparing food and operating a tin opener. Operating a tin opener is part of the preparing food responsibility.
In conclusion I see these three things providing new ways to organise code. In the Model View Controller world the application is broken up by functionality. As an application grows you can find yourself with a large application that is still only broken into three clean pieces, the model layer the view layer and a controller layer. Instead we can move to separating code around features. As an application grows it gets more features and the number of distinct pieces grows. This is good because each can be understood in isolation.
John Conway first theorized that it would be impossible to create a forever-expanding universe using these rules, which was proven wrong by a team at MIT, creating the “glider gun,” which is featured in the third gif.
Since then, thanks to computers, people all over the world have added new designs to the database, creating amazingly complex designs.
For example Andrew J. Wade created a design which replicates itself every 34 million generations! Furthermore it is also a spaceship (permanently moving pattern) and not only that, it was also the first spaceship that did not travel purely diagonally or horizontally/vertically! These types of spaceships are now appropriately named Knightships.
The simulation has some interesting properties, for example it has a theoretical maximum speed information can travel. Or simply, light speed - as that is the limit in our own universe. The limit is set to 1 cell per generation - after all how can you create something further than 1 cell away in one generation if you can only effect your immediate neighbours? And yet you can get things like the ‘stargate’ (Love the name, huge SG fan here.) which allows a space ship to travel 11 cells in just 6 generations.
Some smart people have even designed calculators, prime number generators and other incredibly complex patterns.
You can create your own patterns here: http://www.bitstorm.org/gameoflife/
All gifs were made from this video: https://www.youtube.com/watch?v=C2vgICfQawE
It's been too long since I had a post I could use to share a few interesting links so this post is only interesting links.
First up some Ruby
I have been building an application over the last few weeks with a greater scope than any I have done before. Following the mantra of fat model I have always aimed to move logic into the models. I not have the situation on obese models and need to break them up further.
This post has a good overview of the problem and what an active record model should not do.
From code climate this one has some good advice on where to start breaking up these models.
One assertion that I have read a few times recently is that authorization logic should remain in the controller. I have followed this but as I have introduced admin and content owners and public pages this has caused my controllers to grow more than I am happy with. This is a good overview of using exceptions to manage complexity but I would still be intrigued to read further arguments on why this logic can't be pushed to the controller.
Next the Javascript
Node Webkit. That sounds cool, this guys blog also has a whole bunch of stuff. Onsen sounds fun too. Polyfills as a service, why the fresh not, from the financial times guys.
This article is not an exciting new tech but just quite a nice overview of several JavaScript hacks.
Python time
I have a growing urge to program in python and this post is a good example of some of the stuff the python community is leading the way in. So also needed is a MEGA-tutorial. Check.
Yeoman describes itself as the 'The web's scaffolding tool for modern webapps'. When I first looked at yeoman, a few months ago, I very quickly dismissed it as not for me. The main reason I did is it looked liked a magical wrapper around Grunt and Bower. Calling itself a scaffolding tool I thought I would hide many of the implementation details that I thought I should be learning. I also foresaw very little benefit atop mastering grunt and bower individually, which looked like they were doing the majority of the work.
Well I have started looking again and I have changed my mind drastically. I decided I needed to look again after watch this excellent talk from Paul Irish. Yeoman fulfils one role fantastically and that role is as a demonstrator. When pushing yourself to learn new techniques I find myself looking at a lot of other peoples code. This is great but most of the time you find yourself looking at a finished product. This means that the implementation details such as build steps are hidden around all the actual code. Trying to learn about simple grunt tasks by looking at the JQuery repository will feel overwhelming. Even though you might be aware that you should only need to look through their grunt file you are never sure if something they are running in the gruntfile is dependent on a particular structure elsewhere in the repo. This is were Yeoman steps in, Yeoman's scaffolds are all the unglamorous bits of a project with all the excitement of the application stripped away.
Being a scaffolding system it is opinionated, many of the individual scaffolds are not overly flexible. Being a relative newcomer however studying these scaffolds has ended up me arriving at the realisation that the workflows promoted in these proto applications are superior to what I was managing on my own. I now make frequent use of Yeomans webapp scaffold.
Getting started with yeoman.
Read about grunt, bower, node & npm. You don't need a deep understanding of any one of these. However understanding what each is for can be useful when working out how the whole thing fits together.
With that out of the way lets get started. Assuming that npm is up and running yeoman is installed using
npm install -g yo
yo then becomes a global command. Running yo brings up a helpful list of options which will walk you through things like finding and installing a generator (project template) as well as building a new project from a template.
All yeoman generators are separate packages and can be installed directly with npm. To install the webapp generator and use it.
npm install -g generator-webapp
mkdir newProject
cd newProject
yo webapp
Next steps
Open the project and have a look around. Even if you never use a generator in one of your own projects you will learn a lot.
An ever present consideration when making software is it's maintainability. A code's maintainability is tightly linked to its accessibility, how easily the next person looking at it can understand it. To make code understandable it must either have a familiar structure, be broken into manageable sensible chunks or perhaps both. There are several guiding principle is to achieve this. Reduce coupling and and increasing cohesion and the Single Responsibility principle are all about this goal.
Following a given structure is a common practise for Rails developers and can produce great results. However what happens when one section begins to grow and the standard structure no longer offers further division. This happened to me recently with the front end JavaScript code. As it depended on more user click events, I rapidly entered a callback hell.
The solution, the publish subscribe pattern. There are standalone pieces of code that you can use to implement this. A really good one is pubsubz from Addy Osmani. However it seamed small enough for me to roll my own version.
Principles
A globally accessible object is responsible for passing a messages that is triggered on one channel to all subscribers of that channel. The other objects in the software system are only activated by broadcasts on the channel they listen to and can only communicate the results they generate by broadcasts. Importantly they will have no idea who is listening.
As an example a completed ajax callback may take the returned data and broadcast that new data is available. A separate object can then write the data to the screen. The original ajax object does not know or care what happened to the data it retrieved.
Advantages
The events are universal and can easily be re-purposed. In the example above if data is loaded by another means, perhaps from local storage, the same event can be fired and with no further changes it will be written to the screen. Tests and logging can be added implemented on the same events.
Disadvantages
If an event is lost, for example objects are broadcasting on channel while the screen writer is listen on a different on, are lost permanently. There is no true/false return for successful completion of an action. In reality this is normally a good thing as waiting for those confirmations particularly in asynchronous code leads to alot of code spaghetti. However when testing it was something that I learnt to check first when tests where failing.
Implementation
Control object
The singleton pattern is very useful for this as it is imperative that all calls to broadcast reach the same object. The following code creates a tower instance the first time it is called and in all subsequent calls returns the first created instance.
(function (global) {
var instance;
function init(){
instance = // code goes here ...
return instance
}
global.Belfry = {
getTower: function(){
if (!instance) {
instance = init();
}
return instance;
}
};
}(this));
Subscribing
Each channel is an array on a channels object. When subscribing a function to a channel the function is added to the corresponding array.
function subscribe(topic, reaction){
var channel = channels[topic] = channels[topic] || [];
channel.push = reaction;
}
Publishing
When a broadcast is made each function in that channels array is called with the content that is to be added to the broadcast.
function publish(topic, content){
_.each(function(action){
action(content, topic);
})(channels[topic] || {});
}
And that is in essence the components of a pubsub. Checkout my library belfry to see a full implementation. There are several embellishments, such as the ability to unsubscribe. The functionality is also curried as this allows broadcast functions for individual channels to be generated which can then be passed around. This reduces the chances of broadcasting on the wrong channel.
This pattern is closely related to other approaches. This is a nice explanation of some of those. I have also tried using events instead of callbacks after watching this talk on the observer pattern.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
I have been using Jasmine running in the browser to test my JavaScript for a while now. Coming from the background of RSpec the syntax is reassuringly similar. However running tests in the browser has several downsides. First there is a rather annoying html file that is required to hold the code and tests together. Second running the tests like this means opening up a browser and moving away from the terminal. This is an annoyance most of the time and completely unsuitable to work with continuous integration. The solution to both this problems is to work with a command line tool, in this case karma.
Karma runs on node.js and is easiest installed using the node package manager (npm). If you have not got either of these installed checkout my post on getting started with node and npm.
Karma is a test runner and requires a test framework to work with. Supported frameworks are jasmine, qunit and mocha. A discussion of the differences between these is beyond this post. In summary I chose Jasmine as it is the most complete without add ons.
Karma also requires a browser to run the tests and a plugin to handle that browser. Supported browsers are Chrome, ChromeCanary, FireFox, Safari, PhantomJS, Opera and InternetExplorer.
Getting started the first step is to initialise a node project then add the test dependencies to package.json.
"devDependencies": {
"karma-jasmine": "~0.1.3",
"karma-phantomjs-launcher": "~0.1.1",
"karma": "~0.10.6",
"karma-spec-reporter": "0.0.12",
}
Running 'npm install' will install all of the packages locally to node. At this point to run any of the karma commands you will be required to enter the whole path, to run the tests for example is likely to be.
$ ./node_modules/karma/bin/karma start
This is tedious and fortunately karma also has a tool to add these commands to your path. To add the command karma to the terminal the package karma-cli needs to be installed globally.
$ npm install -g karma-cli
$ karma start // same as long command above
The configuration settings are kept in karma.conf.js. Here you set how you would like to format the output, whether to run continuously and what files to load. There are a lot of whys to set up karma, this is my preference.
An important thing to note is to remember to load up all your dependencies, also when using wildcards the files will be added in alphabetical order. When the order is important then that will need to be declared specifically. It took me a while to spot that one as the first three projects I did the correct order was alphabetical order
I always use the test suite as a single run through. As the test suites I have written so far take less than 1 sec I have always been happy to explicitly run them. This also works well with continuous integration.
Finally the 'spec' reporter is not included by default and needs to be added through node
$ npm install karma-spec-reporter --save-dev
That's getting started with karma, but doesn't cover writing any of the tests. That is because karma can run many different flavours of tests. A simple test framework to start with is Jasmine, which has an exceptionally clear introduction to the basics and several more powerful techniques. There is also a great supply of plugins for handling fixtures, asynchronous code and more. Because Jasmine offers such a complete solution I have not always found it the easiest to integrate plugins with. For this reason I want to try mocha which is an alternative test framework that can be run on karma, and will hopefully be reported on in the future.
I have been exploring functional programming over the last few weeks, and rather enjoying it. The topic is huge and so far I have only scratched the surface. This post is an explaining of my two favourite concepts so far, currying and composition. Taken individually they are useful but combined can perform so very powerful operations.
All of the examples will be in JavaScript as it is very easy to pass around functions. in fact this is one of the reasons I like JavaScript.
Currying
I have found it best described as a way of incrementally declaring arguments. Currying relies on the fact that functions can return functions. First some code for a function to add two numbers, in what could be considered as the classic way.
var add = function(a, b){
return a + b;
};
add(3, 5)
=> 8
This code is very simple and appears to have no downsides so why would you change it. The hidden downside is that it requires you to provide both 'a' & 'b' at the same time. Contrast with the curried function below
var add = function(a){
return function(b){
return a + b;
};
};
var add3 = add(3);
add3(5);
In this code first the value of 3 is passed to the add function. This creates a brand new function that will always add 3 to which the value of 5 is passed. This may not seam that revolutionary but can be very useful with operations that are often used. e.g calculating a tax percentage at always 17.5%.
Function composition
Composition is the process of 'piping' the output of one function 'f' to the input of a second 'g' before the first input is present. In the process creating a third function 'h' which is the equivalent of sequentially applying 'f' then 'g'.
h(x) = g(f(x))
This is all very theoretical and will be better explained by an example. Imagine we want to add 3 to a number and then double the result.
First lets introduce a curried multiply function similar to the curried add function.
var multiply = function(a){
return function(b){
return a * b;
};
};
Then we create the components of add3 and double
var add3 = add(3);
var double = multiply(2);
We can then pass both of these to our compose function and just use the resulting function.
var operation = compose(double, add3)
operation(1)
=> 8
operation(3)
=> 12
The benefit of this is it allows us to set up very sophisticated operations, all describe in one variable, before any of the data has arrived. The 'dumb' data is then manipulated in very few steps and intermediate often uninteresting variables are skipped over.
Implementation
Function composition is simple in theory but it implementation can be more tricky, due to complexity in preserving the composed function's context (what the 'this' object refers to when executing the function). Solving this requires a good understanding of JavaScripts bind, call and apply. Ideally implementation details would be taken care of and the functionality described above would be available in a Library.
To this end I have been developing 'cumin.js' a functional utilities library to experiment with these techniques. To build a solid base I have started by reflecting much of the functions available in underscore.js. The single rule is that the data should come last. This is explained in this great talk 'Hey Underscore, your doing it wrong' from Brian Lonsdorf.
Do take a look at cumin. Its far from finished but it tries to show off this and other powerful functional ideas. In addition to the standard test suite there are also example tests that show more possibilities, such as calculated hypotenuse length in nDimensions and working with country data. There are more coming and welcome contributions could be to have some more examples added.
Because of JavaScript's unique place as the browser of the browser it is a slightly different flavour of packet manager. Bower is built to use git and allows you to gather remote packages that you can then use in your web application. Where bower differs from others is that, unlike npm for node, it is not responsible for loading the packages into your runtime environment.
Getting Bower
Bower itself is a node package and so first you must ensure that your system has node and npm. You can see my blog post on starting with these. Now you have these on your system you can start with bower. Install Bower globally with the following command.
npm install -g bower
Bower packages
Packages can be installed directly and bower will save the them to the bower_components directory by default.
bower install <package-name>
Bower can also use a bower.json file to install packages. There is an init function that will interactively create one, providing helpful defaults for name and version.
bower init
If you are only creating a private project this file is most useful for saving dependencies. Packages can be manually added to the json file. The install command also includes a switch to automatically save installed packages
bower install <package-name> --save
In the future running bower install will automatically install all dependencies mentioned in the json file.
There are a huge number of available packages, from simple utilities to full frameworks such as ionic.
Registering a package
Running off git it is fantastically easy to create a bower package. First make sure that the bower.json file is created and contains information such as name, author and keywords. Then the package can be registered using
bower register <name> <url>
The name is the name the package will be registered under and has to be unique. The url is to a public git repository where the package is located. And that's it.
Built on top of git creating a new release is as simple as tagging a commit in your repo and pushing it to the remote storage.
Using Bower
Registering a package is so simple that I have found it an easy way to manage code even within projects. Recently I have been writing an application to manipulate SVG images. During development I have created several useful utilities that I wanted to factor out of the main code base. Instead of storing them in separate files, but still in the main repository, and combining them using a grunt task. I have added them as bower packages. This makes them far more accessible to future projects. Most importantly this has made them available to others and helps to grow opensource code bases. Something that I can feel good about even if they may not have been used by anyone. My bower packages so far are:-
Cumin, utilities library favouring curried functions and functional operations
Belfry, a simple publish subscribe library returning curried functions to work with cumin
SoVeryGroovy, convenient API for generating SVG components
Hammerhead2, The main graphics functionality calling all the above as dependencies
An excellent introduction to Microservices and why to use them. I was annoyed to have missed this talk but the video is good and I hope to be getting to more of these meetups in the future.
For balance is this article Microservices - Not a free Lunch. which is mentioned in the talk
JavaScript is a language that was designed and built initially to only run in the browser. At the time this required it to be very lightweight. Ass JavaScript was typically being delivered from untrusted sources certain features were unnecessary or worse a security problem. For example a webpage has no need to access your computers file structure and so this was omitted from the language.
Node puts these missing features that every language require back in. This means that you can run JavaScript applications outside the browser. What Node isn't is a server framework/librabray. Express and many others build upon Node to make a web application framework.
What is Npm?
Node packaged modules (npm) is the official package manager for Node. It fills the roll of bundler for Ruby. It facilitates simple downloading, upgrading and tracking of libraries added to a Node application.
Installation
This installation guide has been tested for myself using Linux Mint and should probably work on Ubuntu. The core ppa contains a node version however the ppa maintained by Chris Lea is bundled with npm and provides a very convenient choice for downloading. First add his ppa and the fetch nodejs.
This should have added the command 'node' and 'npm' to your terminal. running 'node' will enter the read evaluate print loop (repl) for node.
Starting a node project
All details of a node project are kept in 'package.json'. This file contains information such as name, author, version number and dependencies. Npm provides an init method which runs a helper to generate the package file. Starting a project looks like this
$ mkdir node-project
$ cd node-project
$ npm init
To install a node package to the project use install with the save switch or optionally the save-dev switch for packages that are only required when testing/developing.
Some packages will need to be installed globally. This is likely the case for ones that are adding a utility to your terminal. Such as 'grunt', 'bower', etc. This is achieved with the global switch
$ sudo npm install -g <name>
Sharing a node project
Packages installed locally will, by default, be saved in the directory node_modules. These dependencies can be populated by npm from package.json and so do not belong in version control. Ensure that you add 'node_modules' to your .gitignore file before committing.
When cloning a node project you will need to add the dependencies. Running npm install with no arguments will fetch dependencies specified in the package file and add them locally.
That covers the basics of starting a project with node. Node is relatively new with its first release in 2009. This article covers why its worth taking notice while this one covers where to use node.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming
My time at Makers Academy has now been over for several weeks. I had hoped for a slight reduction in intensity but that is yet to happen.
At the end of week 12 we had our graduation day. We were told that we were now fully fledged developers, albeit at a junior level but no longer apprentices. The nice thing about this was that I believe it. It seams amazing that we could have progressed so much in twelve weeks but when I look at what I was doing before I realise we have.
First up I took a week off, this I would recommend to anyone following. It helps to remember that a Saturday needn't be spent watching a rails tutorial. So I saw some friends in France and Switzerland and that was all very nice. I discussed the merits of Test Driven Development and Pair Programming with a friend of mine in academia and in return he introduced me to 2048. If you haven't found this yet its probably best to stay that way.
Back to work and the first thing I wanted to tackle was consolidating my knowledge from the course. There were tasks I did not manage to complete as well as many helpful resources that I want to go over. For an idea of just how many useful resources we collected over the 12 weeks check out this repository were we have consolidated some.
Next up was cleaning my Github account. (yes I know this should have happened as I went along). This was the only thing on my list that took less time that expected. I had been trying to write sensible README's as I went along and in most cases a quick overview is all that is required.
Of less importance but most fun was exploring brand new things. Continuous integration is something we heard and I have enjoyed experimented with Codeship. Also automated code review for which I have experimented with Codeclimate. These are both really easy to integrate with Github and I was able to set-up both of these and complete a web based fizzbuzz kata in under 30 mins. To start serious TDD with JavaScript I have explored using Bower, Karma, Grunt, Yeoman and Jasmine-Jquery. All of which are worthy of there own blog post.
With all of these to do's now under control, about three weeks after graduating, I can start to make meaning full progress on finishing off my London Layout App. Thankfully with my new expertise what were serious problems before Makers I can now easily overcome.
And finally I need to become at least a little bit employed. The journey was fun but rather pricey. I have talked to two friends about websites they've had build and in both cases I have been able to confidently say "Yes I could build that". Actually in both cases there were no test so I was able to say "I could build a more maintainable version than that one you paid for". So need a website or app. Get in contact. Once London Layout is in the App stores I could be just the person you are looking for, here is my profile on our final project.
This week I tried my hand at some Python for the first time in a long time. The goal of this was to simply create a 'Hello World!' application on Heroku.
Linux Mint comes with Python as standard and this post will be entirely about working with Mint. The useful tools I set up are on the recommendation of 'Two scoops of Django' and their chapter on environment setup.
First I needed pip, a package management system for software written in python. Second Virtualenv, which is used to create isolated Python environments. This addresses the same role as Ruby Gemfiles and Bundler. These two are installed with apt-get.
Also recommended was the nattily named virtualenvwrapper. This can be installed in the same way but requires some further setup. To set the location of project and the python environments I had to add the following to my bash profile.
With this setup the project can now be started making full use of the tools installed above. Amazingly these tools mean that it is possible to have a project live on Heroku with only 10 commands from the terminal. I have split these into two groups of 5. The first being
$ mkproject hello
$ pip install Flask gunicorn
$ pip freeze > requirements.txt
$ touch hello.py
$ echo 'web: gunicorn hello:app' > Procfile
So what happened here? mkproject is a command from virtualenvwrapper, it creates an environment called hello and and project called hello. Then it switches to the project directory and starts the created environment. Both Flask and gunicorn are python packages that we install to the enviroment. pip freeze lists all packages that are currently in use, saving them to requirements.txt allows Heroku to install the same ones. we then create an application file called hello.py and a Procfile to give instructions on starting the application.
At this point we can write an application in the hello.py file. For a quick example I just used the sample application for Heroku for getting started.
So at this point we have a working application that can be run locally with foreman. Next is to push this to Heroku. These steps should be familiar if you have previously used Heroku however I have listed them below for completeness.
$ git init
$ git add .
$ git commit -m 'init'
$ heroku create
$ git push heroku master
At this point your application is live on Heroku. Running a final 'Heroku open' will open the application in your default browser to prove the point.
These tools are brilliant but this is only the slimmest of introductions. For a fuller overview is this blog post.