Showing posts with label TypeScript. Show all posts
Showing posts with label TypeScript. Show all posts

Monday, 4 May 2015

Helicopters in Vietnam, TypeScript and Generics, Type Definition Files in TypeScript

Helicopters in the Vietnam War

At the end of the Vietnam War, unneeded helicopters were pushed overboard so that the ships would have more room to take rescued troops.

TypeScript and Generics

You can use generics in TypeScript. They're code templates. They're re-useable and flexible. You can use them instead of using the type `any`. The type is supplied when it is used and thus type checking can be enforced for the particular type supplied and wherever that particular thing is used elsewhere in the code.

Type Definition Files

There are type definition files available at the site Definitely Typed for most of the major JavaScript libraries so that you can check whether you are using the library correctly at compile time.

Monday, 27 April 2015

Fantasy Castle, Performance and S3, TypeScript Interfaces

Fantasy Castle

I do love the Guardian's How to Draw... series. I'm pretty terrible at drawing but with their help I get something that doesn't look like a 5 year old drew it. Today I learnt to draw a enchanted forest. I haven't got a fine black pen to go over the pencil, and I definitely need more practice, but for a first attempt I'm happy.

Performance and S3

CDNs (Content Delivery Networks) allow information to be sent to a visitor from nearby. Unfortunately, with Amazon's S3 you are tied to a particular location so although it's cloud storage, it's not going to be delivering stuff locally to the visitor.

TypeScript Interfaces

In TypeScript you can use interfaces to check the classes implement all the parameters and functions as stated. There is no implementation of this in JavaScript so it's purely used as a consistency check at compile time.

Monday, 20 April 2015

Tardigrades, The Command Key and Keyup, TypeScript Classes, Goats in Rwanda

1. Tardigrades

Tardigrades are tiny creatures, around 1mm long that can survive extreme conditions. Some were sent into space on a satellite and not only did many of them survive but they even had healthy young.

These remarkable creatures can survive in a dehydrated state of suspended animation and can even repair damaged DNA when they come out of it. Some of them can survive radiation, extreme heat and extreme cold.

3. TypeScript Classes

The following is a TypeScript class

class Something {
  thing: string;
  constructor (thing: string){
    this.thing = thing;  
  }
}
var something = new Something ('whatever');

which produces the JavaScript

var Something = (function () {
  function Something () {
    this.thing = thing;  
  }
  return Something;
})();

var something = new Something ('whatever');

However, there is a simpler version of the TypeScript that will give the same result.

class Something {
  constructor (private thing: string){  
  }
}
var something = new Something ('whatever');
You can also make it public, which again results in the same JavaScript.
class Something {
  constructor (public thing: string){  
  }
}
var something = new Something ('whatever');

Although the JavaScript is the same, TypeScript will catch errors related to the private field. Note that everything is public by default.

Hope and Inspiration

Goats in Rwanda

It's easy to get bogged down by all the bad news and negative things highlighted around us so I'm going to add a section on stories, blog posts, articles that I find bring hope. The first of these is an article about a family in Rwanda who received a goat from a charity called Heifer International five years ago. It was a life changing event for the family.

Heifer International is an organisation which trains people in better farming practices along with giving them animals and tools to get started. Receiving an animal means the family gets increased food supplies directly through milk or eggs and indirectly through the increased yields of their crops through fertiliser made from dung.

There are other organisation which do this, but the principle that I particularly like about this organisation and their sister organisation Send A Cow, is the "pass it on" principle. The first female offspring of any animal they receive, along with training is passed on to another person, so not only is the first person helped, but they participate in helping another, and the chain continues.

This whole process has dramatic effects on the families receiving gifts. Their health improves through better nutrition. They receive extra income from the abundance of produce. They can afford to send their children to school.

Tuesday, 14 April 2015

Swedish, TypeScript, Control

1. Cheese Plane

I lived in Sweden for seven or eight years. For some things which I hadn't seen before in England, I use the Swedish word. Osthyvel is one of these things.


Wikipedia - Jonas Bergsten

I suppose you could say it's a cheese slicer but there are so many different ways to slice cheese, and this is a particular tool. Well, today, while looking for microplane zesters, I stumbled across an osthyvel at Ocado. They call it a "cheese plane" which is so much more precise than cheese slicer.

2. TypeScript

You can use classes in TypeScript along with private and static. Static properties and functions live on the class, and are shared between all instances. If you make a variable private, then it will only be accessible from within the class.

3.High Control Groups

Four tactics used by high control groups, such as cults, are:

  • Behaviour control,
  • Information control,
  • Thought control,
  • Emotional control.

Saturday, 11 April 2015

Vaccinations, TypeScript, Hebrew Numbers

1. Vaccinations in the UK

It's important for the population for a large percentage (usually somewhere around 90% depending on the disease) to be vaccinated to provide herd immunity (if enough are vaccinated, the disease can't jump from person to person and so is unable to spread much.) Herd immunity helps to protect children too young to have the vaccine, and those who have compromised immune system such as those receiving cancer treatments or with AIDS.

Different countries have different policies to attempt to achieve this. In the article Should childhood vaccination be compulsory in the UK?, I learnt some of the issues determining policies. One of the problems of forcing children to be vaccinated is that it erodes trust between the parents and health provider, and between the parents and government. Parents who do not vaccinate their children tend to do so because of a fear of doing harm, a fear as to the safety of vaccines, or the belief that their child will not catch the infection, or if they do, it will not be severe.

Vaccination in the UK is not compulsory, yet there is a high uptake.

2. TypeScript

TypeScript is a superset of JavaScript which means that any JavaScript file is already a TypeScript file. TypeScript compiles into JavaScript (ES3, ES5 or ES6). It has type annotation, where you declare a type such as in

var x: number = 3;
and type inference, where it knows the type from what you set the variable equal to. In the next example, it infers that x is of type number.

var x = 3;

Since TypeScript is compiled into JavaScript, it has no impact on runtime.

3. Hebrew Numbers

Hebrew numbers are written using the letters in the alphabet, so א is used to represent 1. In order to show that it's the number 1 instead of the letter, it is prepended by ׳ giving ׳א. Numbers not represented by the letters of the alphabet, are formed by summing, so 12 is written using the symbols for 10 (י) and 2 (ב) giving י״ב. The ״ is used to show that it is a number rather than a word. It is placed before the last number (reading right to left) so 780 would be written as תש״פ where פ is 80, ת is 300, and פ is 400. Note that Hebrew is written from right to left, with the usual convention that the smallest number is on the left. There are some exceptions. To avoid writing the names of god, 15 is written as 9+6 ט״ו‎, and 16 as 9+7 ט״ז‎‎. Sometimes the order is rearranged to avoid words with negative connotations.