Skip to content

Instantly share code, notes, and snippets.

Avatar

Mohan Radhakrishnan mohanr

View GitHub Profile
@mohanr
mohanr / ReactiveCompletion.java
Created Jun 6, 2014
CompletableFuture example
View ReactiveCompletion.java
import org.apache.http.HttpEntity;
import org.apache.http.client.fluent.Content;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@mohanr
mohanr / gist:9c79ed88b0e88a76b935
Created May 20, 2015
Add text boxes dynamically using AngularJS
View gist:9c79ed88b0e88a76b935
<div ng-app="app" ng-controller="MainCtrl" ng-init="textboxes = ['Text1','Text2','Text3']">
<div ng-repeat="box in textboxes">
{{box}}
<copyoftextbox ng-model="models[$index]" name={{box}} index={{$index}}></copyoftextbox>
</div>
</div>
var app = angular.module("app", []);
app.controller('MainCtrl', function($scope) {
$scope.models = ['model1','model2','model3'];
@mohanr
mohanr / letter.ml
Last active Dec 6, 2016
Associative List
View letter.ml
let insert l a =
if List.mem_assoc a l
then
let n = List.assoc a l in (a, n+1)::(List.remove_assoc a l)
else (a, 1)::l
let letters (word : string) : char MultiSet.t =
let rec insert (l : char MultiSet.t) (c : string) (i : int) : char MultiSet.t =
if ( String.length c > 1 ) then
insert ( MultiSet.insert l (String.get c i) ) ( String.sub c 1 ((String.length c) - 1) ) 0
@mohanr
mohanr / ocaml.lisp
Created Dec 5, 2016
OCaml Emacs .emacs
View ocaml.lisp
(package-initialize)
(load "/home/mohan/.opam/4.02.1/share/emacs/site-lisp/tuareg-site-file")
(let ((opam-share (ignore-errors (car (process-lines "opam" "config" "var"
"share")))))
(when (and opam-share (file-directory-p opam-share))
;; Register Merlin
(add-to-list 'load-path (expand-file-name "emacs/site-lisp" opam-share))
(autoload 'merlin-mode "merlin" nil t nil)
;; Automatically start it in OCaml buffers
View simulator.hs
module Simulator where
import Numeric.LinearAlgebra
import Graphics.Matplotlib
import Control.Monad.State
import qualified Data.Map as Map
import Text.Printf
import System.Random
import Control.Monad
import Data.Array
import Data.Foldable
@mohanr
mohanr / softmaxtf.py
Created May 11, 2018
Softmax using TensorFlow
View softmaxtf.py
import tensorflow as tf
import numpy as np
v = tf.constant([1.,-2.,0.5])
tv = tf.convert_to_tensor(v,dtype=np.float32)
with tf.Session() as sess:
x = tf.nn.softmax(tv)
tf.Print(x, [x], message="Softmax")
print(sess.run(x))
@mohanr
mohanr / kruskal.ml
Created Dec 25, 2019
A minimal Kruskal MST implementation in Ocaml
View kruskal.ml
type edge = ( int * int * int ) list
module type EDGECOMPARE = sig
type t
val compare : 'a list -> 'a list ->bool
end
module EDGECOMPARE_weight : EDGECOMPARE with type t = edge = struct
type t = edge
let compare l r = ( List.nth l ( List.length l/ 2 )) == ( List.nth r (List.length r/2))
View dune.lisp
(library
(modules graph)
(name graph)
)
(test
(name kruskaltest)
(modules kruskaltest)
(libraries alcotest graph))
View kruskaltest.ml
let testcompare () = Alcotest.(check bool) "Test for weight comparison" true (Graph.EDGECOMPARE_weight.compare [1,2,4] [ 5,6,7] )
let () =
Alcotest.run "Weights"
[
("test compare weights of edges", [
Alcotest.test_case "Compare weights" `Quick testcompare;
]);
]
You can’t perform that action at this time.