Results tagged “Programming”

When working with ember-cli and things seem to get messed up and you cannot figure out for the life of you what's wrong you can always resort to nuking it all and refreshing the environment.

This often helps me alot, and although I do not know for sure the exact details behind the reason it fixes things, I don't care as long as it works.

In my ~/.bash_aliases I've added the following aliases, a "regular" fix nom and a "nuke-it-all-and start-over-again" fix nomallas follows:

alias nom='rm -rf node_modules && npm cache clear && npm install'
alias nomall='rm -rf node_modules && npm cache clear && npm install && rm -rf bower_modules && bower cache clean && bower install'
...
alias realias='$EDITOR ~/.bash_aliases; source ~/.bash_aliases'

Just run realias to make the required changes and you're all set.

The Erlang notation [ F(X) || X <- L] means "the list of F(X) where X is taken from the list L."

1> L = [1,2,3,4,5].
[1,2,3,4,5]
2> [2*X || X <- L ].
[2,4,6,8,10]

Thus, [2*X || X <- L ] means "the list of 2*X where X is taken from the list L."

There's tons of other really really cool stuff you can do. Like qsort(L) for quick sorting lists:

qsort([]) -> [];
qsort([Pivot|T]) ->
	qsort([X || X <- T, X < Pivot])
	++ [Pivot] ++
	qsort([X || X <- T, X >= Pivot]).

Or perms(S) for generating all possible permutations of a string:

perms([]) -> [[]];
perms(L)  -> [[H|T] || H <- L, T <- perms(L--[H])].

Or pythag(N) for generating all Pythagorean triplets (sets of integers {A,B,C} where A2 + B2 = C2):

pythag(N) ->
    [ {A,B,C} ||
        A <- lists:seq(1,N),
        B <- lists:seq(1,N),
        C <- lists:seq(1,N),
        A+B+C =< N,
        A*A+B*B =:= C*C 
    ].

Ad infinitum into the wee hours of the morning...

The absence of side effects means that we can parallelize our software programs.

The technical term for memory areas that can be modified is mutable state. Erlang is a functional programming language and has immutable state.

If you use a conventional programming language such as C or Java to program a multicore CPU, then you will have to contend with the problem of shared memory.

In order not to corrupt shared memory, the memory has to be locked while it is accessed. Programs that access shared memory must not crash while they are manipulating the shared memory.

In Erlang, there is no mutable state, there is no shared memory, and there are no locks. This makes it easy to parallelize our programs.

jaerlang2_xlargecover.jpg
Programming Erlang (2nd edition)
by Joe Armstrong

All the code runs inside lightweight threads of execution (called processes) that are isolated and exchange information via messages.

Due to their lightweight nature, it is not uncommon to have hundreds of thousands of processes running concurrently in the same machine. Isolation allows processes to be garbage collected independently, reducing system-wide pauses, and using all machine resources as efficiently as possible (vertical scaling).

Processes are also able to communicate with other processes running on different machines in the same network. This provides the foundation for distribution, allowing developers to coordinate work across multiple nodes (horizontal scaling).

The unavoidable truth about software running in production is that things will go wrong. Even more when we take network, file systems and other third-party resources into account.

To cope with failures, it provides supervisors which describe how to restart parts of your system when things go awry, going back to a known initial state that is guaranteed to work.

elixir-logo.png

The future is uncertain, but I remain adamant and well-prepared for whatever might come my way.

That's why I decided to sharpen my programming skills further by refreshing my knowledge of Ruby, Rails and Ember. Lots of reading and practicing to do, great stuff to look forward to figuring out.

Long live convention over configuration.

I'm never too old to learn new stuff. Perhaps I should just retire early and become a gardener for fun and relaxation (not).

ember-mvc.png

This is the way that ember.js does it.

Completed and solved my first problem of the year. I know that today is only the first day of the year, but why wait when there are so many interesting challenges to pursue in life? Here is what I encountered on the RubyMonk website.

Problem Statement:
Given a 3 or 4 digit number with distinct digits, return a sorted array of all the unique numbers than can be formed with those digits.

Example:
Given: 123
Return: [123, 132, 213, 231, 312, 321]

My solution:

def number_shuffle(number)
  number.to_s.split(//).permutation.to_a.map {|a| a.join.to_i }
end

Tutorial solution:

def number_shuffle(number)
  no_of_combinations = number.to_s.size == 3 ? 6 : 24
  digits = number.to_s.split(//)
  combinations = []
  combinations << digits.shuffle.join.to_i while combinations.uniq.size!=no_of_combinations
  combinations.uniq.sort
end

My solution is not only conciser but in my opinion more elegant as well. Applying Occam's razor principle here, I'll let you decide for yourself

Rails enhances the flexibility of Ruby nicely. It allows built-in classes to seamlessly include extra fancy methods which sound like human language.The elegance and power of Rails is leveraged atop the malleability of the underlying Ruby language. Here's some proof:

kiffin@F5SL:...orial-hartl/sample_app $ rails console
Loading development environment (Rails 4.0.2)
>> 1.year.from_now
=> Sun, 21 Dec 2014 14:20:37 UTC +00:00
>> 10.weeks.ago
=> Sat, 12 Oct 2013 14:20:47 UTC +00:00
>> 1.kilobyte
=> 1024
>> 5.megabytes
=> 5242880

See Learn Web Development with Rails by Michael Hartl for a great introduction to Rails.

The quote below is taken from the MOOC I am following on BerkeleyX which is called CS.169.2x Software as a Service, part 2 (Refactoring and Legacy):

"... or we could do it the more principled way which is cover and modify, which means, let good test coverage be your security blanket. If you've got a good test suit, then when you make changes that breaks something, your test switch had tip you off to that fact, because you'll have regression test and plays. You'll know if you broke something." -- Armando Fox

Of the many software companies who were interviewed, more than eighty percent state that the most important skill lacking in modern day software engineers is the ability to deal successfully with legacy code.

Learning the ML programming language is a lot of fun. This is my first in-depth initiation into the exciting world of functional programming. Here's something to whet your appetite, an elegant function for appending two lists of any type:

fun append e =
    case e of
        ([],ys) => ys
      | (x::xs,ys) => x :: append(xs,ys)

Here we are passing the function append an expression e, and if the pattern matches empty string plus string we stop, otherwise we prepend the first element to the tail appended to the list.

I am following the online Coursera training by the University of Washington called Programming Languages given by Dan Grossman.

Great stuff to keep my aging brain cells oiled and running efficiently.

  1 2

Random entries

Here are some random entries that you might be interested in:

Recent Assets

  • 2024-03-Heren1-27h.png
  • three-body-problem.png
  • 10CC.png
  • minds-and-machines.jpeg
  • puglia.png
  • 2023-09-24-jong-tegen-oud-1.jpg
  • 2023-09-24-jong-tegen-oud-2.jpg
  • just-call-me-fred.png
  • foggy-morning.png
  • oma-2023-07-27.jpg
  • i-almost-died.png
  • chipping-from-twenty-meters.png

Recent Comments

  • Long time no see: I remember them, as well. I remember Donald was my ...
    - Charles
  • Bridge to the moon: Yes it was a drawing and my older brother told me ...
    - jpmcfarlane
  • Bridge to the moon: Wow, that's quite a coincidence that we both sent ...
    - Kiffin
  • Bridge to the moon: Hello I was in my teens when Gemini 4 went up that ...
    - jpmcfarlane
  • Back to work: Congratulations Kiffin, I hope it is something you ...
    - KathleenC

Golf Handicap

Information

This personal weblog was started way back on July 21, 2001 which means that it is 7-21-2001 old.

So far this blog contains no less than 2510 entries and as many as 1877 comments.

Important events

Graduated from Stanford 6-5-1979 ago.

Kiffin Rockwell was shot down and killed 9-23-1916 ago.

Believe it or not but I am 10-11-1957 young.

First met Thea in Balestrand, Norway 6-14-1980 ago.

Began well-balanced and healthy life style 1-8-2013 ago.

My father passed away 10-20-2000 ago.

My mother passed away 3-27-2018 ago.

Started Gishtech 04-25-2016 ago.