Skip to content

Instantly share code, notes, and snippets.

@shehaaz
shehaaz / flip_flop.ml
Created December 12, 2013 02:14
Fun with References: Write a function flip_flop :- unit -> (unit -> int) flip_flop: Generates a function that takes in UNIT and produces INT. Every time the generated function is called with unit it either produces "0" or "1" e.g: let ff = flip_flop();; ff();; >1 ff();; >0 ff();; >1 ...
let flip_flop () =
let counter = ref 0
in
fun () -> (if(!counter = 0) then counter := 1 else counter := 0; !counter);;
@shehaaz
shehaaz / gist:7921325
Created December 12, 2013 00:42
OCaml Question: Write a function to sum all the ODD numbers between a & b (a is guaranteed to be smaller than b)
let sumOdd a b =
let rec inner a b =
if a>=b then b else a + (inner (a+2) b)
in
let (new_a,new_b) =
(
(if ((a mod 2) = 0) then (a+1) else a),
@shehaaz
shehaaz / gist:7165109
Created October 26, 2013 03:56
Ocaml Option Example
# let x = Some "test";;
val x : string option = Some "test"
# match x with
|None -> Printf.printf "saw none\n"
|Some v -> Printf.printf "saw %s\n" v;;
saw test
- : unit = ()
@shehaaz
shehaaz / Loopj.java
Last active December 22, 2015 11:18
LoopJ Android Http PUT
AsyncHttpClient client = new AsyncHttpClient();
JSONObject jsonParams = new JSONObject();
timestamp = String.valueOf(calendar.getTimeInMillis());
jsonParams.put("body", postBody);
jsonParams.put("price", postPrice);
jsonParams.put("location", location);
jsonParams.put("user", bargain_user.getName());
jsonParams.put("user_id", bargain_user.getUser_ID());
jsonParams.put("image", base64Image);
jsonParams.put("store_id", storeID);
@shehaaz
shehaaz / Runner.java
Created April 1, 2013 02:39
Cassandra Runner
public class Runner {
/**
* @param args
*/
public static void main(String[] args) {
CassandraDAO c = new CassandraDAO();
ResultSet result = c.findByCQL("Select * from user_profiles");
@shehaaz
shehaaz / CassandraDriver.java
Last active December 15, 2015 15:09
Cassandra Java Driver
package com.example.cassandra;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Query;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.exceptions.NoHostAvailableException;
<a href="http://twitter.com/mybloggertricks" class="twitter-follow-button">Follow @mybloggertricks</a>
<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>
@shehaaz
shehaaz / LISP
Created October 26, 2012 08:24
Test Lisp Snippet
(defun call-random (m n)
"(m n)
Call (random n) m times. Used by seed-random."
(do ((i 0 (1+ i)))
((= i m) nil)
(if (zerop n)
(random 1)
(random n))))
;;;file: r.cl