Saturday, July 20, 2013

Functors, Applicatives, and Monads
  • Functor
    • Functors apply a function to a wrapped value:
    • Easy example to remember it by:  getPostTitle <$> (findPost 1)
    • A value can be in a context. Now when you apply a function to this value, you’ll get different results depending on the context. 
    • A Functor is any data type that defines howfmap applies to it. 
    • The Maybe data type defines two related contexts: we’ll see how function application is different when something is a Just a versus a Nothing
    • When a value is wrapped in a context, you can’t apply a normal function to it:This is where fmap comes in
  • Applicatives
    • Applicatives apply a wrapped function to a wrapped value:
    • Easy example to remember it by: Just (+5) <*> (Just 3)
    • Applicatives allow you to apply a function that takes two arguments to two wrapped values?
  • Monads
    • Monads apply a function that returns a wrapped value to a wrapped value.
    •  > Just 20 >>= half >>= half >>= half

http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html

Friday, July 19, 2013

Temporarily ignore file checked in to git

So, to temporarily ignore changes in a certain file, run:
git update-index --assume-unchanged <file>
Then when you want to track changes again:
git update-index --no-assume-unchanged <file>

http://gitready.com/intermediate/2009/02/18/temporarily-ignoring-files.html

Tuesday, July 16, 2013

Software Engineering Points

I have tried to distill some knowledge that has come from building a few green field projects. These are the three points that have come about from this experience.
  • Focus on building up a language of "higher concepts" that are relevant to your system.
    • As your system progresses into later stages of development the hope is that you will be able to begin to spend more time applying the "higher concepts" you built in earlier stages.
  • Naming, Modularization, and Code Organization should not be under estimated.
    • Giving modules a well defined purpose and exporting a public interface is crucial. While it may not affect how the the code works it allows you to think at a higher level and keep less information in your brain at once. KISS
  • The eventual goal is to build software that is "product ready", in other words you want to be able to release the software and leave it alone.
    • If you have to hire a big IT team to support your software maybe you can improve your code to be more self sufficient.

Git pick out individual commits

The following approach was easy and straightforward to migrate some code on a branch that had diverged greatly from the current one. I was able to grab a specific commit out.

git format-patch -1 b50788b
git am 0001-First-pass-at-rake-task.patch

http://gitready.com/intermediate/2009/03/04/pick-out-individual-commits.html

Tuesday, July 9, 2013

A Resilient RPC Infrastructure with Thrift Finagle ServerSets Zookeeper

One use case for ZooKeeper within Twitter is service discovery. Finagle services register themselves in ZooKeeper using our ServerSet library, see finagle-serversets. This allows clients to simply say they’d like to communicate with “the production cluster for service a in data centre b” and the ServerSet implementation will ensure an up-to-date host list is available. Whenever new capacity is added the client will automatically be aware and will start load balancing across all servers.

http://blog.oskarsson.nu/post/40196324612/the-twitter-stack

Great tutorial on building a Finagle Search Service, http://twitter.github.io/scala_school/searchbird.html

Another interesting article on unique id generation, https://github.com/twitter/snowflake/

Distributed databases, http://en.wikipedia.org/wiki/Gizzard_(scala_framework)

http://thrift.apache.org/

http://twitter.github.io/finagle/guide/

Thursday, May 23, 2013

Spring, Camel consumer shutdown hack


import java.lang.reflect.Field;
import java.util.List;

import org.apache.camel.Consumer;
import org.apache.camel.spring.remoting.CamelServiceExporter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.SmartLifecycle;

import amqp.spring.camel.component.SpringAMQPConsumer;

/**
 * Bean to help shutdown Camel beans that do not have a doStop() method that does what's needed to shut them down
 *
 */
public class AmqpConsumerShutdownBean implements SmartLifecycle {
@Autowired(required = false)
List<CamelServiceExporter> camelExports;
private boolean running = false;
public AmqpConsumerShutdownBean() {
}

@Override
public void start() {
this.running = true;
}

@Override
public void stop() {
if (this.camelExports == null) {
return;
}
for (CamelServiceExporter bean : this.camelExports) {
Field f = null;
try {
f = bean.getClass().getDeclaredField("consumer");
f.setAccessible(true);
Consumer consumer = (Consumer)f.get(bean);
consumer.getEndpoint();
if (consumer instanceof SpringAMQPConsumer) {
consumer.getEndpoint().stop();
((SpringAMQPConsumer) consumer).doShutdown();
f.set(bean, null);
bean.destroy();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (f != null) {
f.setAccessible(false);
}
}
}
this.running = false;
}

@Override
public boolean isRunning() {
return this.running;
}


@Override
public int getPhase() {
return 1;
}

@Override
public boolean isAutoStartup() {
return true;
}

@Override
public void stop(Runnable callback) {
if (this.isRunning()) {
this.stop();
}
callback.run();
}


}

Wednesday, May 15, 2013

Google I/0 2013 Take aways


Some amazing things that came out of the introduction to the conference.
  1.  Google all access pass looks cool, basically you pay 10 bucks a month for unlimited access to music via Google Play.
  2. WebM has two important parts Webp for pictures and VP9 for videos. Extreme compression to shrink media down to a small size, especially useful for streaming video.
  3. Web components and actions aka build you own html tags, could be cool, but I am not sure.
  4. Google+ hangouts with history
  5. Google highlight allows you to instantly pick the photos from a album that are worth keeping. It works by detecting blurry or duplicate photos, bad exposure, landmarks, happy people, aesthetics, affinity. It uses machine learning to do all the work. Happy people is worth noting as it tries to detect smiles and other characteristics of the emotion -- prioritizes those pictures.
  6. AutoEnhance uses algorithms to automatically make your photos look as if a professional enhanced them. It uses tonal distribution, noise reduction, white balancing, and skin softening among others to do the magic!
    1. Because of some break throughs in computer vision, it can identify individual parts of the face. The skin, hair, and other pieces of the anatomy can be found to determine if the person in the picture is wearing glasses or jewelry, ... etc
  7. Knowledge Graph is now being expanded to many more entities. 
  8. Google Voice Experience is very fast and accurate. Watch out Siri!

Google Maps has some really impressive new features coming.

  1. Map maker is cool in what it has allowed people to accomplish. We now have some of the best maps of a particular area from user contributed sources.
  2. 3D photo tour shows interiors of buildings automatically via photo sphere.
  3. Zagat is now integrated into Maps to allow you to see reviews without leaving.
  4. Maps are now customized to you, it shows you how your friends reviewed a place.
  5. Clicking on a placemark will show you important roads around it.
  6. Google maps Schedule Viewer is pretty sweet, it allows you to compare how using different means of transport will get you to your destination.
  7. Google earth is now integrated into Maps!
    1. When zooming out it even shows you the earth inside the solar system. This includes an accurate representation of the stars.