The political arena is getting out of hand. Media conglomerates with deep pockets are trying to censor the web. Are they crazy? Censoring the web will not bring more money into their pockets, but will instead shut down another channel of their income. Sigh.
This is our last stand to stop these bills (SOPA & PIPA) from passing.
If you’re reading this it means you are surfing the web. I suggest you join us in fighting against these bills:
http://americancensorship.org/
January 17th, 2012 in
Blurb |
No Comments
Microsoft has recently announced that they will be launching their very own App Store? What does this mean? It means big. Microsoft has a huge chunk of the computer users. Simply by providing this App Store, developers can easily reach out to a larger set of users.
See: http://www.forbes.com/sites/briancaulfield/2011/12/07/with-new-windows-app-store-microsoft-is-hoping-size-matters/
For developers, the question is, how can I capitalized on this? Once Microsoft’s App Store is realized, developers would have 3 app ecosystem to work with: Android, iOS, and now Windows based.
It will be interesting to see how all of this folds out. Only time will tell.
December 7th, 2011 in
Blurb |
No Comments
http://sysgears.com/comment/1302
Nice and easy way to do increments in mongodb through the Java driver. There is a gotcha that one need to make sure of. I spent about an hour trying to figure out why my update didn’t work correctly.
When updating through mongodb, you need to specify the search query and also your update doc. If you’re searching by “_id”, make sure you create an ObjectId.
1
2
| DBObject search = new BasicDBObject("_id", new ObjectId("your id string"));
coll.update(search, newdoc); |
https://plus.google.com/112678702228711889851/posts/eVeouesvaVX
Very honest and insightful post. I especially like the platform thinking.
Hopefully Google doesn’t take this down.
October 12th, 2011 in
Blurb |
No Comments
Here’s Problem 22. Another easy one.
/*
P22 (*) Create a list containing all integers within a given range.
Example:
scala> range(4, 9)
res0: List[Int] = List(4, 5, 6, 7, 8, 9)
*/
1
2
3
4
5
6
7
| def range(start:Int, end:Int) : List[Int] = {
if (start > end) throw new Exception("Start cannot be greater than end")
start match {
case v if start < end => v::range(start+1,end)
case v => end::Nil
}
} |
/*
P21 (*) Insert an element at a given position into a list.
Example:
scala> insertAt(‘new, 1, List(‘a, ‘b, ‘c, ‘d))
res0: List[Symbol] = List(‘a, ‘new, ‘b, ‘c, ‘d)
*/
1
2
3
4
5
6
7
8
| def insertAt[T](item:T, index:Int, list:List[T]) : List[T] = {
list match {
case (head::tail) if (index <= 0) => item::head::tail
case (head::tail) if (index >= list.length) => head::tail:::List(item)
case (head::tail) if (index > 0) => head::insertAt (item,index-1,tail)
case _ => list
}
} |
Pretty easy solution. However, this solution is a bit slow as we are prepending to the end of the list. A better solution is to create the list dynamically.
/*
P20 (*) Remove the Kth element from a list.
Return the list and the removed element in a Tuple. Elements are numbered from 0.
Example:
scala> removeAt(1, List(‘a, ‘b, ‘c, ‘d))
res0: (List[Symbol], Symbol) = (List(‘a, ‘c, ‘d),’b)
*/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| def removeAt[T](index:Int, list:List[T]) : (List[T],T) = {
if (index < 0 || index > list.length)
throw new IndexOutOfBoundsException("Index is out of bounds")
def removeAt2(index:Int, left:List[T], right:List[T]) : (List[T],T) = {
right match {
case (head::tail) if (index == 0) => (left:::tail,head)
case (head::tail) if (index > 0) => removeAt2(index-1,left:::List(head),tail)
case Nil => throw new IndexOutOfBoundsException("Index is out of bounds")
}
}
removeAt2(index,Nil,list)
} |
Problem 19. Pretty straight forward. I have questions on the use of “:::”. There must be a better way.
/*
P19 (**) Rotate a list N places to the left.
Examples:
scala> rotate(3, List(‘a, ‘b, ‘c, ‘d, ‘e, ‘f, ‘g, ‘h, ‘i, ‘j, ‘k))
res0: List[Symbol] = List(‘d, ‘e, ‘f, ‘g, ‘h, ‘i, ‘j, ‘k, ‘a, ‘b, ‘c)
scala> rotate(-2, List(‘a, ‘b, ‘c, ‘d, ‘e, ‘f, ‘g, ‘h, ‘i, ‘j, ‘k))
res1: List[Symbol] = List(‘j, ‘k, ‘a, ‘b, ‘c, ‘d, ‘e, ‘f, ‘g, ‘h, ‘i)
*/
1
2
3
4
5
6
7
8
9
10
11
| def rotate[T](radix:Int, list:List[T]) : (List[T]) = {
if (radix < 0) {
// make this positive
rotate(list.length+radix,list)
} else {
list match {
case (head::tail) if radix > 0 => rotate(radix-1,tail:::List(head))
case _ => list // if we're at the end, then just return the list
}
}
} |
I got somewhat bore so decided to go back to the Scala Problems.
Here’s the solution to Problem 18:
P18 (**) Extract a slice from a list.
Given two indices, I and K, the slice is the list containing the elements from and including the Ith element up to but not including the Kth element of the original list. Start counting the elements with 0.
Example:
scala> slice(3, 7, List(‘a, ‘b, ‘c, ‘d, ‘e, ‘f, ‘g, ‘h, ‘i, ‘j, ‘k))
res0: List[Symbol] = List(‘d, ‘e, ‘f, ‘g)
1
2
3
4
5
6
7
8
| def slice[T](start:Int, end:Int, list:List[T]) : (List[T]) = {
list match {
case (head::tail) if start > 0 => slice(start-1,end-1,tail)
case (head::tail) if start <= 0 && end > 0 => head::slice (start,end-1,tail)
case (head::Nil) => head::Nil
case _ => Nil
}
} |