Skip to content

Instantly share code, notes, and snippets.

View krishnabhargav's full-sized avatar

Krishna Vangapandu krishnabhargav

View GitHub Profile
@krishnabhargav
krishnabhargav / trip.clj
Last active August 29, 2015 14:06
some clojure code to get some experts review it ..
(ns trip.core
(:require [[clj-time.core :as t]
[clojure.set :as set]]))
(defn default-trip
"returns a default trip with current date as start date & end date as 5 days from now"
[]
{ :name "New Trip"
:description "Enter your trip description here"
:start-date (t/today)
@krishnabhargav
krishnabhargav / project.clj
Last active August 29, 2015 14:06
web development blog's project.clj
(defproject webapp "0.1.0-SNAPSHOT"
:description "Web Application in Clojure"
:url "http://localhost/groupie"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[ring "1.3.1"]
[http-kit "2.1.16"]
[compojure "1.1.9"]
@krishnabhargav
krishnabhargav / server.clj
Last active August 29, 2015 14:06
clojure server
(ns webapp.server
(:require [ring.middleware.resource :refer [wrap-resource]]
[ring.middleware.file-info :refer [wrap-file-info]]
[ring.middleware.reload :refer [wrap-reload]]
[compojure.core :refer :all]
[compojure.route :as route]
[org.httpkit.server :refer [run-server]]))
(defroutes route-map
@krishnabhargav
krishnabhargav / client.cljs
Last active August 29, 2015 14:06
simple hello alert message
(ns webapp.client
(:require
[figwheel.client :as fw :include-macros true]))
(fw/watch-and-reload)
(js/alert "Hello Zumanji")
@krishnabhargav
krishnabhargav / index.html
Created September 23, 2014 01:44
clojurescript included html file
<html>
<body>
Welcome to clojure world!
<script type="text/javascript" src="js/goog/base.js"></script>
<script src="js/main.js" type="text/javascript"></script>
<script text="text/javascript">
goog.require("webapp.client");
</script>
@krishnabhargav
krishnabhargav / fib.scala
Created October 21, 2014 03:14
Functional Scala ... tail recursive computation of fib number
//tail recursive fibonacci numbers
def fib(n: Int) = {
@scala.annotation.tailrec
def fibImpl(a:Int, nxt: Int, res: Int) : Int =
a match {
case 0 => res
case _ => fibImpl(a-1, nxt+res, nxt)
}
fibImpl(n, 1, 0);
}
@krishnabhargav
krishnabhargav / isSorted.scala
Created October 21, 2014 11:52
isSorted for arrays and seq
def isSorted[A] (items : Seq[A], ordered : (A,A) => Boolean) : Boolean =
(items, items.tail).zipped.forall(ordered)
/*items match {
case null => true
case x :: Nil => true
case x :: y :: xs => ordered (x, y) && isSorted (xs, ordered)
}*/
isSorted(Seq(1,2,3), (a: Int, b: Int) => a < b);
@krishnabhargav
krishnabhargav / curry.scala
Last active August 29, 2015 14:08
implementing currying ... chapter 2 ... FP in Scala
def curry[A,B,C] (f: (A,B) => C): A => (B => C) = a => b => f(a,b)
curry((a:Int, b:Int) => a * b)(1)(2)
def uncurry [A,B,C] (f: A => B => C) : (A,B) => C = (a,b) => f(a)(b)
var f = uncurry (curry((a:Int, b: Int) => a * b)) // f (3,5) = 15
@krishnabhargav
krishnabhargav / compose.scala
Created October 25, 2014 14:13
f compose g in Scala .. Chapter 2 FP In Scala
def compose[A,B,C] (f: B => C, g : A => B) : A => C = a => f(g(a))
@krishnabhargav
krishnabhargav / WebsocketServer.scala
Created November 12, 2014 13:43
Websocket server inside a scala application
import org.atmosphere.config.service.WebSocketHandlerService
import org.atmosphere.nettosphere.{Config, Nettosphere}
import org.atmosphere.websocket.{WebSocket, WebSocketHandlerAdapter}
object Main {
def main(args: Array[String]) {
val builder = new Config.Builder().host("127.0.0.1").port(8080)