When receiving JSON data from other resources(server API etc), we need Json.Decode to convert the JSON values into Elm values. This gist let you quickly learn how to do that.
I like to follow working example code so this is how the boilerplate will look like:
import Graphics.Element exposing (Element, show)
import Task exposing (Task, andThen)
import Json.Decode exposing (Decoder, int, string, object3, (:=))
import Http
import Graphics.Element exposing (Element, show) | |
import Task exposing (Task, andThen) | |
import Json.Decode exposing (Decoder, int, string, object3, (:=), at, keyValuePairs) | |
import Http | |
type alias Languages = | |
List (String, Int) | |
mailbox = |
;; ------------------------- | |
;; BMI Calculator | |
(def bmi-data | |
(reagent/atom {:height 180 | |
:weight 60})) | |
(defn slider [min max val param] | |
[:input {:type "range" | |
:value val | |
:min min |
Should be work with 0.18
Destructuring(or pattern matching) is a way used to extract data from a data structure(tuple, list, record) that mirros the construction. Compare to other languages, Elm support much less destructuring but let's see what it got !
myTuple = ("A", "B", "C")
myNestedTuple = ("A", "B", "C", ("X", "Y", "Z"))
I realised the design of database becomes more and more trivial to me when it comes to refactoring of application or scaling.
In web application frameworks like Ruby on rails and CakePHP there is a feature known as counterCache
. This feature let you record the length of associated data, mostly when they have belongsTo
relationship.
This feature is very convenient but it is not applicable to all database design. For example, when we never want to delete user data when she did it, most probably we will add a column like delete_flag
in our table. So when user deletes the data, delete_flag
will become 1 or true. Our select sql query looks like:
SELECT * FROM table_name WHERE delete_flag=0
Back to counterCache
, it mainly do 2 thing.
- increase the counter when data is inserted
Repost from:
http://yangweilim.com/blog/2015/11/18/clojure-thread-first-vs-thread-last-macros/
In this post, I am going to show you {when|how} to use Clojure marcos, ->>
aka thread-last and ->
aka thread-first. In some case, ->
and ->>
may perform the same operation if you do not pay enough attention. So I will also show you what's the difference between them. Note that doc ->
and docs ->>
din't make sense for me at first, so if same thing happened to you I hope that this post will make it clear.
If I am coding a function in Clojure, I would not think to write in macro firstly(maybe I am still new to it?). Macros like ->
and ->>
only come in my mind when it comes to refactoring. They are not neccessary in our program but they will make it elegant.
To explain how both of these macros work, let's us solve a quiz together.
[Write a function which calculates factorials.](http://www.4clojure.com/prob
- Servers for Hacker
- Laracasts - The Best PHP Screencast on the web
- Rails Casts - Ruby on Rails Screencast
- egghead.io - Front end stuff (JavaScript, Angular.js, React.js)