Skip to content

Instantly share code, notes, and snippets.

View hhimanshu's full-sized avatar
🚀
Building meaningful products

Harit Himanshu hhimanshu

🚀
Building meaningful products
View GitHub Profile
@hhimanshu
hhimanshu / Chapter01.json
Created August 25, 2015 23:13
ElasticSearch: The definitive guide
GET _search
{
"query": {
"match_all": {}
}
}
PUT /megacorp/employee/1
{
"first_name": "John",
@hhimanshu
hhimanshu / README.md
Created August 11, 2015 18:17
Vim Tmux Setup
@hhimanshu
hhimanshu / Scala.For.The.Impatient.md
Last active September 28, 2021 15:51
Scala for the Impatient Exercises

This gist will contain all the exercises from the book

@hhimanshu
hhimanshu / P06.scala
Created June 7, 2015 21:28
P06 (*) Find out whether a list is a palindrome.
package com.learner.s99
/**
* P06 (*) Find out whether a list is a palindrome.
* Example:
* scala> isPalindrome(List(1, 2, 3, 2, 1))
* res0: Boolean = true
*/
object P06 {
def isPalindrome[T](l:List[T]):Boolean = l == l.reverse
@hhimanshu
hhimanshu / P05.scala
Created June 7, 2015 20:55
P05 (*) Reverse a list.
package com.learner.s99
/**
* P05 (*) Reverse a list.
* Example:
* scala> reverse(List(1, 1, 2, 3, 5, 8))
* res0: List[Int] = List(8, 5, 3, 2, 1, 1)
*/
object P05 {
def reverse[T](l:List[T]): Option[List[T]] = reverse(l, Nil)
@hhimanshu
hhimanshu / P04.scala
Created June 7, 2015 05:36
P04 (*) Find the number of elements of a list.
package com.learner.s99
/**
* (*) Find the number of elements of a list.
* Example:
* scala> length(List(1, 1, 2, 3, 5, 8))
* res0: Int = 6
*/
object P04 {
@hhimanshu
hhimanshu / P03.scala
Created June 7, 2015 05:18
P03 (*) Find the Kth element of a list.
package com.learner.s99
object P03 {
def nth(n: Int, l: List[Any]): Any = {
require(n >= 0, "n must be greater than or equal to zero")
l match {
case List() => None
case head :: tail if n == 0 => head
case head :: tail if n > 0 => nth(n - 1, tail)
}
@hhimanshu
hhimanshu / P02.scala
Created June 7, 2015 04:40
P02 (*) Find the last but one element of a list.
package com.learner.s99
/**
* (*) Find the last but one element of a list.
* Example:
* scala> penultimate(List(1, 1, 2, 3, 5, 8))
* res0: Int = 5
*/
object P02 {
def penultimate(input: List[Any]): Any = penultimate(input, None, None)
@hhimanshu
hhimanshu / P01.scala
Last active August 29, 2015 14:22
P01 (*) Find the last element of a list.
package com.learner.s99
/*
(*) Find the last element of a list.
Example:
scala> last(List(1, 1, 2, 3, 5, 8))
res0: Int = 8
*/
object P01 {
### Keybase proof
I hereby claim:
* I am hhimanshu on github.
* I am harit (https://keybase.io/harit) on keybase.
* I have a public key whose fingerprint is 04F0 0F7B 4775 E8EF 5B3B 2836 E703 AF72 5E8D EFF3
To claim this, I am signing this object: