A kind of function that is only applicable to certain input values. Partial function can be useful for error detection, and knows how to deal with invalid inputs. The emphasis is that partial function will do something else if an input is not accepted.
Partially applied function
A function that has been partially applied. Say if a function requires two parameters, we can only apply the first one but leave the second one. Later on we can apply this partially applied function with the second argument.
123
defdividedBy(a:Int,b:Int)={a/b}valtenDividedBy=dividedBy(10,_:Int)tenDividedBy(10)// should be 1
Currying
It could easily be confused with partially applied function. I’d like to think of currying as a subset of partially applied function. We decompose a function with multiple parameters into a chain of functions taking one argument at a time.
So, what’s the difference?
Passing a block in a function can be syntactically concise
1234567891011
defeachOfMap(m:Map[String, Int])(fn:((String,Int))=>Unit)={m.foreach(fn)}valaMap=Map("a"->1,"b"->2,"c"->3)eachOfMap(aMap){case(str:String,in:Int)=>println(s"$str, $in")}// a, 1// b, 2// c, 3
This post is intended to document the basic configuration I do for a typical EC2 Ubuntu instance, just want to make my life easier without googling the same thing all over again.
It’s already July! Omg time flies when it comes to summer time.
Update: recently I’ve been very involved in my internship project. I can’t expose the detail but basically I am working with AngularJS extensively. Though I am still very far from an experienced AngularJS developer, I must say IT IS A BEAUTIFUL WEB FRONT-END FRAMEWORK.
Currently I am working on a project called “yolyo” (temporarily name), which is based on an open source forum Discourse. Since Discourse requires quite a bit of computing resources, I decided to use Amazon EC2 as our starting point. As I realized how important it is to configure a virtual instance, I would like to dedicate this post to document all the works I’ve put into to make things work smoothly.
First of all, I would like to thank BitNami providing one-click Discourse installation to deploy on EC2. Otherwise, I would’ve still struggled with all the nitty gritty deployment detail.
How to deploy/update by Git
This has confused me for a long while. I had been used to deploy virtually everything by drag and drop for so long. Though I’ve learnt how to use Git to do versioning, I do not know how to setup the cloud server so that I can simply do git push origin master to deploy the changes.
Although I finally figured out how to use Git to deploy remote instance, I realized this workflow doesn’t work really well with Discourse. Discourse itself already contains a git repo, so I would need to push to a remote repo and deploy the instance by pulling from this remote repo. (If anyone knows a better deployment strategy, please let me know)
On remote machine
create a git repo as a transition to deploy to a designated directory
Copy local machine public key to the remote server (ec2 instance)
#!/bin/sh## This hook does two things:## 1. update the "info" files that allow the list of references to be# queries over dumb transports such as http## 2. if this repository looks like it is a non-bare repository, and# the checked-out branch is pushed to, then update the working copy.# This makes "push" function somewhat similarly to darcs and bzr.## To enable this hook, make this file executable by "chmod +x post-update".git update-server-info
is_bare=$(git config --get --bool core.bare)if[ -z "$is_bare"]then# for compatibility's sake, guessgit_dir_full=$(cd$GIT_DIR; pwd)case$git_dir_full in */.git)is_bare=false;; *)is_bare=true;; esacfiupdate_wc(){ref=$1echo"Push to checked out branch $ref" >&2
if[ ! -f $GIT_DIR/logs/HEAD ]thenecho"E:push to non-bare repository requires a HEAD reflog" >&2
exit 1
fi if(cd$GIT_WORK_TREE; git diff-files -q --exit-code >/dev/null)thenwc_dirty=0
elseecho"W:unstaged changes found in working copy" >&2
wc_dirty=1
desc="working copy"fi if git diff-index --cached HEAD@{1} >/dev/null
thenindex_dirty=0
elseecho"W:uncommitted, staged changes found" >&2
index_dirty=1
if[ -n "$desc"]thendesc="$desc and index"elsedesc="index"fi fi if["$wc_dirty" -ne 0 -o "$index_dirty" -ne 0 ]then
Make hooks/post-update executible
1
$ chmod +x post-update
On local machine
I’m lazy to explicitly write out the steps here. I will just refer to the StackOverflow page that helped me solve this problem.
Side note
After all the above hassle I suddenly realized that I do not need any of these setup. Because I shall rely on a remote (e.q. GitHub) to host the repo, so the remote machine can easily pull from this remote repo. Though it is true that I am not currently working collaboratively with anybody else, this is a good deployment/development practice.
Today is the second day of the summer, and I feel pretty good about having a fresh start despite the fact that I did waste yesterday just to have beers with my friends. All in all, life’s good after the final exams, YAY!
This summer I will be working on Ruby on Sinatra, along with some light-weight front-end framework. Therefore, in order to get ready for my internship, I am setting up a reading list so that I don’t just blindly work on something without understanding the fundamentals.
Although I don’t think the project I will be working on requires any kind of sophisticated front-end work, I still want to learn the trendy hipster-ish front-end JavaScript frameworks like AngularJS, KnockoutJS, or EmberJS.
Here is the reading list of the books and the useful tutorials:
So far I found Ruby very magical and pseudo-intuitive to learn, but as coming from a less-dynamic programming language, I sometimes found I am doing too much work for what should’ve been done in two lines of code. I need to practice write less code in Ruby to achieve maximum efficiency. I will continue to update this list as I found useful resources.
Alright, I know the title is a bit off. I could’ve still suffered if I don’t study well enough to handle the finals. I’ve discovered a OSX application called SelfControl to prevent me from wondering on social websites occasionally for a period of time.
This app is really awesome if you are the kind of person like me who lacks self-discipline whenever there is a need to focus. Well, mainly the reason is I don’t really like the material and it is hard in general, so that pushed me off from being proactive about the finals.
Fortunately, this app is powerful enough to keep me from cracking the rules. It claims that after the rules are set, there is no way to break the rules even uninstalling the app. So there you have it! In case someone is looking for some help to get focused studying for exams.
This semester I am taking a self-paced UNIX class, which is a lot more fun compared to the other theoretical-ish computer courses. Sometimes I really lack motivation to learn effective UNIX commands to make my life easier. And I don’t think I’m alone, but in order to be a legit software enginner I must at least not suck at the basics.
Last week I ran to an UNIX tutor asking some dumb questions from the text, and I finally realized that piping is not restricted to a single input command! I wonder why it took me so long to notice this trivial fact, why!!!!????
Here it goes, I need to remind myself how dumb I was/am and hopefully I stay motivated to be an effective engineer.
1
$ cat someFile | comm -12 - anotherFile
It’s the hyphen that makes this works beautifully! Who would have thought of using hyphen? Who?
I have been very busy interviewing for my internship opportunities. And it went quite well despite the fact that I got a rejection from a startup. At first, I was a little bit disappointed about how I blew the second phone interview. However, I quickly resumed my confidence as I kept getting email requesting interviews. Overall, the internship recruiting experience has been positive and I’ve learned tons of tips on things like “how to make your first impression” or “bugging the recruiters you know until you get an interview”. If it wasn’t my sister who is experienced with all of this, I could’ve been still blindly submitting my not-so-impressive resume electronically.
So I ended up taking the offer from Autodesk. Weird right? They are well-known for AutoCAD, and lots of 3D design software suite that are widely used in different industries. But why Autodesk? The most important determinant for me is the degree of impact I would make for a job, as well as the level of experience I would learn from the developers. Also, I originally set up a list of the language or frameworks that I want to learn/master for this summer. It turns out that I am going to use Ruby on Rails as the back-end to develop the project, which is great. Because I really need to learn Ruby on Rails by practical implementation.
I just need to take good care of the rest of the semester and occasionally learn Ruby on Rails from time to time before the first day of my internship! Woot woot!