Skip to content

Instantly share code, notes, and snippets.

View abhin4v's full-sized avatar

Abhinav Sarkar abhin4v

View GitHub Profile
@abhin4v
abhin4v / StarTopologySimulation.scala
Created July 12, 2010 19:28
Simulation of Star network topology using Actors in Scala
import actors.Actor
import actors.Actor._
object StarTopologySimulation extends Application {
case class Message(sender: Node)
class Node(id: Int) extends Actor {
def act() {
val startTime = System.nanoTime
@abhin4v
abhin4v / ring.clj
Created July 15, 2010 19:20
Simulation of Ring network topology using Agents in Clojure
(ns net.abhinavsarkar
(:use [clojure.contrib.import-static]))
(import-static java.lang.Integer parseInt)
(def no-of-nodes
(do
(println "Number of nodes? ")
(parseInt (read-line))))
@abhin4v
abhin4v / unicode-partition.clj
Created August 13, 2010 10:34
function for detecting unicode ligatures in text
(ns net.abhinavsarkar.unicode-partition
(:import [java.awt.font TextAttribute GlyphVector]
[java.awt Font]
[javax.swing JTextArea]))
(let [^java.util.Map text-attrs {
TextAttribute/FAMILY "Arial Unicode MS"
TextAttribute/SIZE 25
TextAttribute/LIGATURES TextAttribute/LIGATURES_ON}
font (Font/getFont text-attrs)
@abhin4v
abhin4v / SnakesAndLadders.hs
Created September 12, 2015 11:37
Simple Snake and Ladders gameplay implementation in Haskell
{-# LANGUAGE RecordWildCards #-}
module Main where
import qualified Data.Map as Map
import Control.Monad.State
import System.Random
import Data.Maybe
import Debug.Trace
main :: IO ()
@abhin4v
abhin4v / swing-auth-input-dialog.clj
Created September 1, 2010 17:56
Creates a JDialog to take the input of username and password from the user.
(defn create-auth-input-dialog
"Creates a JDialog to take the input of username and password from the user.
Returns the dialog.
Arguments are:
parent: the parent frame
dialog-title: the title of the dialog
dialog-message: the message shown in the dialog
dialog-width : the width of the dialog
@abhin4v
abhin4v / Promise.java
Created September 11, 2010 18:14
A promise is a Future which will be fulfilled later by the promise maker
package net.abhinavsarkar.util;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import scala.math.{sin, cos, abs, round, ceil, Pi}
import scala.collection.mutable.Buffer
import scala.util.Random.nextPrintableChar
case class Point(x: Int, y: Int)
class Star(val spikes: Int, val kind: Int, val diameter: Int) {
lazy val vertices: Seq[Point] = {
val radius = diameter/2.0
@abhin4v
abhin4v / SPOJ-PRIME1.hs
Created September 29, 2010 08:21
Solution to SPOJ PRIME1 problem
module Main where
import List
main :: IO ()
main = do
noOfTestCases <- readLn
readTestCases noOfTestCases
readTestCases :: Integer -> IO ()
@abhin4v
abhin4v / socharts.clj
Created December 2, 2010 13:58
Shows Stack Overflow reputations, upvotes, downvotes and accepted answers for a user against the tags for the answers. See http://stackapps.com/questions/1828/socharts-charts-by-tags
; Copyright (c) Abhinav Sarkar. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
(ns socharts.socharts
(:import [java.util.zip GZIPInputStream]
@abhin4v
abhin4v / ascii-bar-chart.clj
Created December 28, 2010 22:34
Prints a horizontal ASCII bar chart for the data given. Written in Clojure.
(defn ascii-bar-chart
"
Prints the horizontal ASCII bar chart for the data given.
Handles both positive and negative values.
Use it to visualize data in the REPL.
Arguments:
data: a seq of key value pairs. the chart is printed in the order of this seq.
keys should be strings (or have a proper toString method).
values should be numbers.