Skip to content

Instantly share code, notes, and snippets.

View DhavalDalal's full-sized avatar
🇮🇳
https://twitter.com/softwareartisan

Dhaval Dalal DhavalDalal

🇮🇳
https://twitter.com/softwareartisan
View GitHub Profile
@DhavalDalal
DhavalDalal / Java -> Menu Actions -> Compile and Run Java
Last active August 29, 2015 14:11
Textmate2 --> Edit Bundle... -->
#!/usr/bin/env bash
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
if [ -e "${TM_FILEPATH}" ]; then
"$TM_BUNDLE_SUPPORT/bin/java_compile_and_run.sh" "$TM_FILEPATH"
else
exit_show_tool_tip "Save the file before running..."
fi
@DhavalDalal
DhavalDalal / Attention.md
Last active March 3, 2023 06:51
Smelly Mars Rover in Java

Smelly Mars Rover (Java)

A squad of robotic rovers is to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rover so that its on-board cameras can get a complete view of the surrounding terrain to send back to Earth.

A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.

In order to control the rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.

Assume that the square directly North from (x, y) is (x, y+1).

@DhavalDalal
DhavalDalal / Attention.md
Last active July 22, 2019 01:03
Smelly Rover in C#

Smelly Mars Rover (C#)

A squad of robotic rovers is to be landed by NASA on a plateau on Mars. This plateau, which is curiously rectangular, must be navigated by the rover so that its on-board cameras can get a complete view of the surrounding terrain to send back to Earth.

A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.

In order to control the rover, NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.

Assume that the square directly North from (x, y) is (x, y+1).

@DhavalDalal
DhavalDalal / Attention.md
Last active April 15, 2019 03:46
Portfolio Tracker.

Portfolio Tracker (Java)

  • Track individual stocks worth and
  • Net worth of the portfolio.

Pre-Requisites

@DhavalDalal
DhavalDalal / Attention.md
Last active March 1, 2022 21:08
Portfolio Tracker in C#

Portfolio Tracker (C#)

  • Track individual stocks worth and
  • Net worth of the portfolio.

Pre-Requisites

  • It requires JSON.NET. You can download it from http://www.newtonsoft.com/json
  • If you are within a proxy, you can do it programmatically like this:
    System.Net.WebRequest.DefaultWebProxy = new WebProxy(ip,port); 
    
@DhavalDalal
DhavalDalal / TopQuery.cs
Created May 20, 2016 14:38
Refactoring in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BeforeRefactoring
{
public class TopQuery
{
public const int DB_ACCESS = 1;
@DhavalDalal
DhavalDalal / Attention.md
Last active April 15, 2019 03:46
DRYing to Exception Monad

DRYing to Exception Monad (Java)

@DhavalDalal
DhavalDalal / TopQuery.java
Last active February 6, 2017 08:33
Refactoring in Java
package beforerefactoring;
public class TopQuery {
public final static int DB_ACCESS = 1;
public final static int DB_ORACLE = 2;
public final static int DB_SQL_SERVER = 3;
public final static int DB_SYBASE = 4;
public final static int DB_OTHER = 5;
private int dbType = -1;
@DhavalDalal
DhavalDalal / ReadMe.md
Last active April 15, 2019 03:47
Dots and Boxes Game

Dots and Boxes (Erlang)

This game is very well described here https://icebreakerideas.com/fun-games-to-play-at-home/#Dots_and_Boxes

Copy pasting the rules here once more.

  • game begins with empty grid of dots
  • players take turns at adding a horizontal or vertical line between two un-joined adjacent dots
  • a player who completes the fourth side of a 1x1 box earns a point, writes their initials in the box and gets another turn.
@DhavalDalal
DhavalDalal / frequency.erl
Created May 2, 2017 12:19
Round-Robin Router
%% Based on code from
%% Erlang Programming
%% Francecso Cesarini and Simon Thompson
%% O'Reilly, 2008
%% http://oreilly.com/catalog/9780596518189/
%% http://www.erlangprogramming.org/
%% (c) Francesco Cesarini and Simon Thompson
-module(frequency).
-export([start/0,allocate/0,deallocate/1,stop/0]).