Monday, August 8, 2016

I'm reviewing data structures and some graph algorithms using Stanford's CS106X

A few weeks ago, I wanted to be able to solve some problems on UVA Online Judge that requires some knowledge of graph algorithms. So I thought of trying to do again the assignments for Stanford's CS106B that I did last 2011.

The problem was that the assignment files that I have requires Visual Studio 2005. I tried to find ways to make it work on VS 2015 but I failed.

So I went to the latest CS106B website to download their latest assignment files (maybe they are using Visual Studio 2015 now?).

... Toinks! I needed to login to download the files. But I'm not a Stanford student! So I was not able to download the files.

Luckily, I found the latest website of CS106X and the files are downloadable. I thought to myself that the problems for CS106X might be more difficult than CS106B's but I think I can be able to do this now because I already experienced solving problems similar to these before.

The handout on the Course Information says that uploading my code to GitHub is a violation to the Honor Code...

The following four activities are among the many considered to be Honor Code violations in this course:
1. Looking at another student's code.
2. Showing another student your code, or making your code public so that it's searchable and easily discovered online or elsewhere.
3. Discussing assignments in such detail that you duplicate a portion of someone else's code in your own program.
4. Uploading your code to a public repository (e.g. github.com or bitbucket.com) so that others can easily discover it via word of mouth or search engines. If you'd like to upload your code to a private repository, you can do so on bitbucket or some other hosting service that provides free-of-charge private hosting.

... so I'm not going to put my code on GitHub or anywhere where anyone can download it. (I placed my solutions online last 2011 when I did CS106B but I already removed them.)

What I'm going to do instead is to put screenshots and the finished executable files of my solutions online just to give proof that I solved the exercises.

You can see the screenshots and executable files of my solutions on my GitHub.

Here is the screenshot of the first problem that I did:



Thursday, August 4, 2016

The Angular 2 "Tour of Heroes" tutorial has a missing part

I think there is something missing in the "Routing" part of the "Tour of Heroes" tutorial -- after the "Make the router available" section and before the "Router Links" section.

The <router-outlet> needs "directives: [ROUTER_DIRECTIVES]". But the code for that is given way below of the tutorial.

I got confused. But I was able to see the error and found a fix for it.

Maybe you got confused also.

Here is the link to what I think should be placed in that missing part. I'm not a native English speaker so my English might not be 100% correct but I believe you can be able to understand it.

Happy coding!


Sunday, July 31, 2016

What is the purpose of "imports" in project.json of .NET Core apps?

I was doing the tutorial "Building Your First Web API with ASP.NET Core MVC and Visual Studio" and after I finished it, I thought of trying to see if Moq will work with .NET Core.


Then I changed the content project.json file with the JSON below whose significant parts came from the "Testing your Console App" section of the tutorial "Getting started with .NET Core on Windows/Linux/macOS using the command line":

Then I tried to remove the "imports" part of the project.json file because I do not know what it was for. But this error pops up in Visual Studio:



... and errors like this in the Output window:
Package xunit.assert 2.1.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package xunit.assert 2.1.0 supports:
- dotnet (.NETPlatform,Version=v5.0)
- portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)

So I tried to look for the purpose of this "imports".

I found the docs for project.json but I do not understand what it is trying to say.

Will cause other packages targeting portable-net45+win8 to be usable when targeting netcoreapp1.0 with the current project.
What does that mean?

Then I tried to google for using this:
more explanation of "imports": "portable-net45+win8"
Google shows only one result which came from StackOverflow which led me to an article from the EF docs. It says this regarding EF:
Some of EF Core’s dependencies do not support .NET Standard yet. EF Core in .NET Standard and .NET Core projects may require adding “imports” to project.json as a temporary workaround.

The workaround is to manually import the portable profile “portable-net451+win8”. This forces NuGet to treat this binaries that match this profile as a compatible framework with .NET Standard, even though they are not. Although “portable-net451+win8” is not 100% compatible with .NET Standard, it is compatible enough for the transition from PCL to .NET Standard. Imports can be removed when EF’s dependencies eventually upgrade to .NET Standard.
That is a much better explanation! Even though I do not know what PCL is :) .

Happy coding!

Sunday, July 10, 2016

My first graph problem solved: "10928 - My Dear Neighbours"

[UPDATE (July 27, 2016): I remember that this is not really the first graph problem I solved. It is, rather, the first graph problem on UVA Online Judge that I solved. I was already able to solve a graph problem when I took the free Stanford course named CS106B last 2011. But I already forgot how I solved it.]

I am so excited!!!

I solved my first graph related problem: the UVA Online Judge's problem #10928 "My Dear Neighbours".

This might just be a very simple problem but at least I am able to get started with solving graph problems.

Picture taken from http://uhunt.felix-halim.net/

Here is my solution:


My actual solution is actually here.

Happy coding!!!

Sunday, May 1, 2016

What does laptop repair shops mean by "replacement" battery?

Last April 1, 2016, pumunta ako sa isang laptop repair shop sa SM City, Ecoland, Davao (name of shop removed to kind of protect the business) para mag-tanong kung dumating na ba yung inorder kong Toshiba laptop battery.

Sabi nung nagbabantay doon ay dumating na daw. Dalhin ko na lang daw yung laptop ko para ma-test yung battery.

So umalis ako at kinuha ko yung laptop ko.

Pagbalik ko sa shop nila, kinuha na niya yung battery. Nang nakita ko ang battery na-disappoint ako dahil hindi pala galing sa Toshiba yung battery.

Nagreklamo ako kung bakit hindi galing sa Toshiba yung battery. Sabi nung nagbabantay ay "replacement" lang daw itong battery so hindi talaga katulad ng original.

Ito yung picture ng original (nasa itaas) at nung "replacement" (nasa ibaba):


At ito yung picture ng resibo para naman hindi sasabihin ng mga nagbabasa na nagsisinungaling ako:


Tapos nung nilagay na yung battery sa laptop, hindi fit, medyo maluwang. Parang nagba-bounce-bounce.

Gusto ko sanang hindi na lang itutuloy yung pag-purchase. Pero dahil may 6 months warranty naman daw e sabi ko na lang sa sarili ko na titingnan ko na lang kung ok ba ang performance ng battery.

So dinala ko na lang yung battery.

Sa first 3 days, palaging 100% yung battery status na nirereport sa screen ko kahit sobra ng 30 minutes nang hindi naka-charge.


Plano ko sana na ito yung gagamitin kong dahilan para ibalik ang battery at makuha ko yung ibinayad ko.

Pero dahil nawala naman after 3 days e binalewala ko na.

Pero hindi umaabot ng 4 hours or 3 hours yung battery ay nade-drain na. Parang 1.5 hours lang yata drained na.

Yun lang :)

I just hope hindi makakasira nga laptop itong battery na nabili ko. hehe


Ang nirereklamo ko lang ay yung pag-gamit ng term na "replacement. "Replacement" din yung ginamit na term noong time na nag-order ako about a month before dumating yung order ko. Akala ko naman yung meaning ng "replacement" ay "tulad ng original".

Gusto ko lang sanang magrequest sa mga laptop repair shops na i-explain na hindi talaga galing sa manufacturer ng laptop ang "replacement" battery na ipinagbibili nila para makapag-decide nang maayos ang customer. :)

Thank you!
I hope hindi kayo magagalit :)


Isinulat ko lang ito para kung sakaling itong battery ang magiging dahilan ng pagkasira ng laptop ko tulad ng nasa mga picture sa article na "Danger: Why You Shouldn’t Buy Cheap Third-Party Batteries For Laptops or Smartphones" ay may masisisi ako hahahaha.


Update:

Well, mabilis umiinit yung battery. After a few months, bigla na lang namamatay yung fan ng laptop ko, at of course bigla din namamatay yung laptop.. tapos napansin ko may bukol yung battery. Pina-tingnan namin sa technician. Sabi ng technician, sira yung board. :(


Sunday, April 17, 2016

My first TDD Kata - String Calculator in C#

I heard about TDD a few years ago but I only appreciated its value after reading some of Robert Martin's blog posts in the past few weeks (and also after having experienced writing post-development unit tests at work).

So today I decided to start doing katas for TDD...


This is my first TDD Kata: https://github.com/jboyflaga2/ProgrammingExercises-CSharp/tree/master/TDDKatas/StringCalculator

There are some things in the specs that I did not include in the implementation. I will just do them next time (really?!).

I found the "specs" for this kata in "Learning Test Driven Development with TDD Katas" by Gaurav Kumar Arora. (But the original author of this kata is Roy Osherove)

This is written in C#.

I used Visual Studio 2015 Community Edition to create a .NET Core project for this kata.

I first planned to use just the Visual Studio Code text editor for this but I was having an error with restoring xUnit. The error was "The dependency xunit.abstractions 2.0.0 does not support framework dnxcore".

I hope this error will be fixed soon.


Let's all learn TDD!!! Happy coding!

Thursday, March 31, 2016

Functional Programming for the Object-Oriented Programmer: My solution to the exercises of the sample chapter I found

I read about the book "Functional Programming for the Object-Oriented Programmer" and Clojure on Uncle Bob Martin's blog.

I am interested in learning about functional programming now because Uncle Bob says in his blog that a functional programming language will be the solution of creating software for a processor with many cores.

I am so excited about learning FP and Clojure so I'm going to post my solutions to the exercises of the sample chapter of the book mentioned above.

(I omitted some parts of the questions. Please download the sample chapter if you want to see the whole questions)


Exercise 1: Given what you know now, can you define a function second that returns the second
element of a list?

(def second (fn [list] (nth list 1)))


Exercise 2: Give two implementations of third, which returns the third element of a list.

(def third (fn [list] (nth list 2)))

(def third (fn [list] (first (rest (rest list)))))


Exercise 3: Implement add-squares.

(def square (fn [n] (* n n)))
(def add-squares (fn [& list] (apply +  (map square list))))


Exercise 4: The range function produces a sequence of numbers:
Using it and apply, implement a bizarre version of factorial that uses neither iteration nor recursion.

(def factorial (fn [n] (apply * (range 1 (+ n 1)))))


I did not do Excercise 5 :)


Exercise 6: Implement this function:
(prefix-of? candidate sequence): Both arguments are sequences. Returns true if the elements
in the candidate are the first elements in the sequence:

(def prefix-of? 
   (fn [candidate sequence] 
      (= candidate 
 (first (partition (count candidate) sequence)))))


Exercise 7: Implement this function:
(tails sequence): Returns a sequence of successively smaller subsequences of the argument.

(def tails 
   (fn [sequence]
      (map 
  drop
  (range 0 (+ 1 (count sequence)))
  (repeat (+ 1 (count sequence)) sequence))))


Exercise 8: In the first exercise in the chapter, I asked you to complete this function:

Mag-create siya ug list with one element inside which is also a list.

(after executing it on the command line)


Ahh I was wrong... "list" is a keyword (or a name of a function)

I googled the error -- I was wrong again -- the reason is because the the literal list is being used as a function. We cannot cast a literal list (I'm not sure if that is how we call it) into a function.