Top Performing CryptoCurrencies

Top Performing CryptoCurrencies

Live Data

This is live data pulled from exchange website. Please refresh if the data was blank. Please continue reading to see how this is done using Azure Functions.

Every time you refresh the page, it will get the current stats. I hope this has been useful.

If you just want to start, Coinbase is an easy way to start, they have a mobile app as well. here is the link: https://www.coinbase.com/join/5a1dcd9998e4f400e08245ba

Programmers Section

Since this is a programming blog, here is how this is done. (Please note I assume you already know how to program)

Many of the Trading sites and LOTS of others, like Twitter and Instagram, provide a Rest API that is open to the public, they don’t need a membership, and provide great info. I’m using https://coinmarketcap.com/ however I don’t know WordPress in depth to create plugins for it, but I know NodeJs, JavaScript, C#, and.Net.

Both Amazon and Microsoft have this concept of Serverless computing, that you can create a whole API and don’t setup a VM or any other server for that matter.

Azure: https://azure.microsoft.com/en-us/services/functions/ is the one I used, Basically Creating a NodeJs app, App calls the Coin Market Cap API and gets the data, cleans it up, and then exposes another rest endpoint. calling that address will kick off this whole process and produces an HTML page that I embedded here.

This whole cycle takes about 35ms!

This help also was very useful: https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node

 

 

CryptoCurrency Hash Types

CryptoCurrency Hash Types

What is Cryptocurrency?

According to wikipedia:

A cryptocurrency (or crypto currency) is a digital asset designed to work as a medium of exchange that uses cryptography to secure its transactions, to control the creation of additional units, and to verify the transfer of assets.[1][2][3] Cryptocurrencies are classified as a subset of digital currencies and are also classified as a subset of alternative currencies and virtual currencies.

If you are not familiar with this concept, please take time to educate yourself, I’ve written couple of blog posts in this regard which you can read, and also wikipedia is a entrance of the rabbit hole 🙂

What is Hash?

Again, referring back to Wikipedia:

A hash function is any function that can be used to map data of arbitrary size to data of fixed size. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes. An example is finding similar stretches in DNA sequences. They are also useful in cryptography. A cryptographic hash function allows one to easily verify that some input data maps to a given hash value, but if the input data is unknown, it is deliberately difficult to reconstruct it (or equivalent alternatives) by knowing the stored hash value.

A Work in Progress Table

# Hash Name Currency Total Possible Website Block Explorer
1 SHA256 Bitcoin 12M
2 Scrypt Litecoin 84M http://www.litecoin.org  http://explorer.litecoin.net/chain/Litecoin
3 X11 Dash 400M http://www.dashpay.io/  https://chainz.cryptoid.info/drk/
4 Scrypt Verge ? https://vergecurrency.com/ https://prohashing.com/explorer/Verge/

I will add more info as time goes by, and also provide a public api for you to use in your excel sheet, or nodejs app.

How to Make sense of JavaScript Universe!

How to Make sense of JavaScript Universe!

 
Recently I gave a talk at Department of Technology about JavaScript, to clarify what are all these JavaScript acronyms and frameworks.
The target audience was managers, supervisors, and those old timers that started coding 20 years ago and heard of JS or even wrote a couple of functions but never could understand what’s going on in JavaScript. They all have heard of Node.js, AngularJs, TypeScript, lint, and even Karma, but what do they mean, if they are somehow JavaScript, then why there are so many names?
If you have similar questions, then keep reading, this article will try to clarify this.
After reading this article, you can answer the following questions:
  • How JavaScript fit into programming languages?
  • What is ES5, ES6, ECMAScript, ES 2015?
  • What is Transpiler?
  • What is polyfill?
  • What is Node.js?
  • what are NPM and yarn?
 Please note this a complete overview aka intro article.

What is JavaScript?

 

Despite the mention of the “Script” word in JavaScript, JavaScript is an independent language. On the surface, it has a familiar semantics as Java, but it is also familiar if you are coming from C# and PHP, but being a functional language it is totally different syntax as Scheme, or Haskel, or Scala!
Why am I mentioning these languages?
Well, All the bazillion Programming languages can be categorized into only two categories. (Yes, you can argue that there is more and go super philosophical about it, more deets on Wikipedia: https://en.wikipedia.org/wiki/Programming_paradigm, but in my opinion, the following two categories would be a great start for organizing languages especially if you are new to this)
1- Imperative
2- Functional
C#, and Java will go into the first category (Imperative) think about them as English with different accents or vocabulary base, Writings of Shakespeare is in English, and so is Think and Grow rich, yet they are so different.
JavaScript, Scala, Haskel, Scheme, and LISP, are part of the 2nd category (Functional).
out of the functional languages mentioned above, JavaScript has the most familiar syntax for imperative languages and even is trying to imitate Class, and Object-Oriented Design, especially with the introduction of ES6.
Although a JavaScript Class might look like C# Class, under the hood, they are totally different,
anyways, as I mentioned earlier I’m just trying to provide an overview, and digging deeper into the nuances and design specs for each language is not part of the scope and nor I do have all the expertise and knowledge.

What is ES6? (ECMAScript)

ES6 is referring to ECMAScript 2015 (the 6th edition of ECMAScript). You can read about it in more details at Wikipedia, or the official website: ecma-international.org.
Complete specifications of ES6 aka ES 2015 can be read at http://www.ecma-international.org/ecma-262/6.0/
Basically, with the new specs, JavaScript will get new features, It is a similar concept for C# 3 to C# 7. Or .Net Framework versions. There are features in the newer language specs that did not exist in the previous version.
Here is one of my favorites, Spread operator:
Assume we have an array of numbers and we want to find the maximum between these numbers:
var numbers = [361,9,95,19];
We could just use IF this was not an array:
var max = Math.max(361,9,95,19);
 With the new spread operator, we can do it like this:
var max = Math.max(…numbers);
 That’s it! One of the greatest benefits of the spread operator is inserting an item in Front of an array. inserting something at the end of an array is very easy, we just do a push. Assume we have an array called “array” and we want to insert a “newItem” in front of it:
var array = [newItem, …array];
 Unfortunately not all the features and operators that are proposed in the ES6 are implemented universally, it is up to each JavaScript engine provider to provide these new features.

What is a Transpiler?

So if you are writing javascript for Chrome Browser, it uses Google’s V8 engine, which has 97% of the ES6 features. But, if you also want to support IE11, it only supports 11% of these new features.  oops! that’s a problem.
before I go to how the community is trying to solve this problem, I wanted to mention a valuable resource on the compatibility. There is a project called Kangax, It is really awesome! you can see all the browsers, polyfills, and servers and see how many of these features they are implementing.
My favorite part of the site is the left side. All the features of ES6 are listed, and there is a little arrow on the right side of that box. if you click on that, all the different aspects of that feature are listed and also there is a sample test code on how to evaluate that. This is one of the best learning tools.
ok, now to solve this incompatibility, one of the approaches is that you write your javascript in ES6 style, and then use a Transpiler (kind of Compiler-ish) to convert (Transpile) your ES6 code to the ES5 code which has a much more compatibility.
Babel, for example, is one the popular transpilers in this regards.
Basically, you write the code in ES6, and use Babel, to convert it to ES5, and then run your code. The process can be automated at development time, that your code gets transpiled, minified and stored in “build” folder, which then you can reference it in the browser.
Or it is possible to include the transpiler in the webpage, this way your code will be transpiled at runtime. this approach might be acceptable for desktop browsers, but definitely not a good idea for mobile and tablet.

What is TypeScript?

Another side effect of this Transpilation (if that’s not a word, it should be 😉 is the invention of a new Typed language called TypeScript, it is similar to the “classic” JavaScript but also has its own features. From the official website of typescript: http://www.typescriptlang.org/
     TypeScript starts from the same syntax and semantics that millions of JavaScript developers know today. Use existing JavaScript code, incorporate popular JavaScript libraries, and call TypeScript code from JavaScript.
     TypeScript compiles to clean, simple JavaScript code which runs on any browser, in Node.js, or in any JavaScript engine that supports ECMAScript 3 (or newer).
Here is how it works:
After writing your code in typescript, you will use typescript compiler to compile the TypeScript to the “classic” JavaScript.
There is a great playground on the typescript website that you can see how this transpilation works, and also you can experiment with it without installing anything on your machine.
TypeScript is created by Microsoft and is now one of the Official supported languages at Google. Google has an elaborate process to internally adopt a language, (usually takes 2 years).

 How Node.js fits into this whole story?

Up until a couple of years ago, the main presence of JavaScript was in the browser world. It is also worth mentioning that the document object, that is extensively used in web development ONLY exist in browsers. so TypeScript and pure JavaScript has no notion of the document object or window object; so commands like document.getElementById(“demo”); Window object and in general the whole HTML DOM object only make sense in a browser.
Node.js uses Google’s V8 JavaScript Engine, and makes it possible to write javascript that runs on the server! So now all the web developers that already knew javascript, could also write server-side code. JavaScript in both Client and Server makes total sense!
As I mentioned this is just an overview, but if you would like similar articles but more in-depth, or you want to have a workshop or presentation for your company, just drop me a line or comment on this post, and I’ll do my best to provide that.
You can learn more Node.js at Wikipedia or Official Node.js website
Official Website: https://nodejs.org/en/

What is npm?

As the community around Node.js grew, they started creating packages (modules) that everyone could use, like a package for converting numbers to Roman Numerals, or creating WebApi, or sending emails, and thousands more. The most common way of managing these was by using a small but awesome utility called npm: Node Package Management. or Node Package Manager. Recently there is also a new kid in the block called yarn, that in essence does the same thing. These tools can also be referred to as Dependency Management tools.
Again, since this is just an overview, we won’t dig deep into these, but if you want to start a new Node.js application, first download and install Node.js, then you can do:
npm init
and answer a couple of questions. Now you have a npm  ready application. you can create index.js file and make it a Node.js application, or you can add some other libraries and make it React or Angular application.
Assuming we want a Node.js app, you have to create an index.js file, this would be the point of entry for your application.
 If we want to add logging, there is a package called winston, we can just install it like:
npm install winston –save
and then in our index.js file we can use it:
var winston = require(“winston”);
winston.log(‘info’, ‘Hello distributed log files!’);
winston.info(‘Hello again distributed logs’);
 You can run your node.js app by typing
node index
 In Part two of this “how to make sense” article, I’ll try to do a brief overview of JavaScript testing, (Jasmine, Karma, Mocha, Chai ….) and Linting, and mention some other popular libraries, like Lodash, jQuery, Breeze, …
I hope this will give you a good overview of JavaScript world so that you can see how these different components fit together.
If you don’t have pluralsight, I recommend checking it out, it is a great learning tool.
Learning Tools:
Happy Coding 🙂
Parallel programming with just two lines of code!

Parallel programming with just two lines of code!

Use all the CPU Power and take advantage of parallel programming with just two lines of code!

Yup, That’s correct, with two lines of code.
Note: If you want to download the source code for the code that is used here, please sign up here and get the source.
In general, Parallel programming is very difficult, you have to know about Threads, Multi-Threading, Cancellation Tokens, Deadlocks and all kinds of weird things that might happen if you are just starting in this area.
Recently in our team meeting, I talked about a very simple but super powerful class in .NET that only has 3 methods.
you might have already used it, but for the rest of us, that just found about it this very cool.
In System.Threading.Tasks namespace, there is a class called “Parallel“. It has only 3 methods, with a bunch of overloads for those 3 methods.
Parallel.For
Parallel.ForEach
Parallel.Invoke
The most basic usage of the first two is very easy to implement. In fact, if you already have a CPU intensive loop somewhere in your code, you just replace it with Parallel.For, and make it 2 to 6 times (or more) faster. (results may vary, depending on the type of loop and CPU Threads)

Let’s look at an example:

To demonstrate how this works, let’s create a simple function that his main purpose is to make the computer brain busy 🙂
 It is going to loop through numbers with small increments.
Now that we have a function that keeps the computer busy, let’s create a function to use it:
Great. Now let’s just set the maximum iterations to 5000, in case of our code, howMuch would be 5000. This means that our loop starts at 1 and increases 0.01 every iteration until it reaches 5000.
The biggest clue that your program is running on a single Thread is checking the CPU performance diagram.
As you can see it is almost using 30% of the CPU, which is the sign that we are running on a single thread. And the amount of time this took is about 8 seconds:
Please note that on your machine, this will vary depending on your processor speed.
Now let’s convert this code to Parallel. The first thing that I should point out is that regular For is a keyword and Parallel.For is a function call!. This function has 12 overloads! the simplest one that we are going over in this introduction is similar to a regular for:
Parallel.ForInfo
The first argument is the start of the counter, the 2nd one is the end number, which in case of int, it will be incremented one by one, for example, Parallel.For(1, 100, ….) will run 99 tasks in parallel, (the to is exclusive, but from is inclusive) and the 3rd argument is the body of the loop as Action.
The more advanced For function call will look like this:
Parallel.ForInfo2



Ok, now let’s convert our simple for loop to a Parallel.For:
Huh, Pretty simple. The only thing that changes is how we initialize the For loop, the rest of the code in the body did not change at all!
Let’s see the performance now,
WOW!, that’s almost 8 times faster! and we only changed 2 lines of code. Using Parallel instead of sequential, if there is ONLY CPU involved, is usually 6 to 8 times faster. but if for example you are reading the content of all the files in a folder, and counting how many times a word is repeated, there are other factors to consider, besides CPU computations, you will have File Access, if the files are on a network driver, then Network performance should also be considered.
Now if you see the CPU graph, you should see you are using 100% of the CPU
This simple call can boost the performance of your application many folds, but there are couple of things that you should consider:
  • First, this example was super simple,  you can do more interesting things, like knowing the state of the loop, and running the iterations in parallel.
  • The second point is if you have a break;  in your normal loop, that would not work in the parallel world. There is no context to break out of, instead, you would use return; this will return from the thread and release it to be used for another iteration.
  •  The third point is that the result of the order of execution is not always sorted from 1 up, meaning if you have a loop that is doing 10 iterations, iteration 9 might finish before iteration 2, and iteration 3 might be the last one!
I showed Parallel.For here, but Paralel.ForEach is a similar idea/syntax, but Parallel.Invoke is a little different in that regard that it will take an array of Actions, and runs them in parallel.
Parallel.Invoke.PNG
When you run this code, the results are NOT in the same order because it ran in parallel, as mentioned above, whichever Thread finishes first, will print the results. so you might get:
Third...
First...
Second...
and next time you run it, it might be:
First...
Third...
Second...

I hope this brief introduction was enough to get you excited and dig deeper into the Parallel world.

Source code: Download ParallelExample.cs

 

If you don’t have pluralsight, I recommend checking it out, it is a great learning tool.
Learning Tools: