Skip to content

Instantly share code, notes, and snippets.

View vingkan's full-sized avatar

Vinesh Kannan vingkan

  • Nuna
  • San Francisco, California
View GitHub Profile
@vingkan
vingkan / datacompression.js
Created November 13, 2015 23:07
To explain JSON compression and decompression.
/*
* This is not to be confused with compression of files.
*/
// Object in decompressed form:
var object = {
name: "Mohsin",
feelings: {
type: "happiness",
intensity: 10,
@vingkan
vingkan / windowfocusblur.js
Created November 14, 2015 10:17
Show two simple approaches to determining if the user is on a given tab/window.
/*
* Using HTML5 Visibility State
* Triggers when user goes to a different tab
* Triggers when user minimizes browser
* Does not trigger when user opens another window on top of browswer
*/
document.visibilityState;
setInterval(function(){
@vingkan
vingkan / QuarantineMeasure.java
Created July 1, 2017 20:28
Quarantine control measure recommended by Team Alpha for Lake Spore outbreak in Lake Town.
/*
* RESULTS WITHOUT CONTROL MEASURE
* 311 people were infected.
* Quarantined 0 people at cost of $0.00
* Outbreak Length: 51.416666666666664 days.
* RESULTS WITH CONTROL MEASURE
* 81 people were infected.
* Quarantined 314 people at cost of $381,390.00
* Outbreak Length: 27.458333333333332 days.
*/
@vingkan
vingkan / server-arena.txt
Last active July 16, 2017 01:28
Battleship Mission 01 Output with DeltaShip
Initial Map
00 01 02 03 04 05 06 07 08 09
00 ~~ ~~ ~~ ~~ [D7][D7] ~~ ~~ ~~ ~~
01 ~~ ~~ ~~ [D7] ~~ ~~ [D7] ~~ ~~ ~~
02 ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
03 ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
04 ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
05 ~~ ~~ ~~ ~~ ~~ [D2] ~~ ~~ ~~ ~~
06 ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
07 ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~~
@vingkan
vingkan / FriendlyFireExample.java
Last active July 20, 2017 00:20
Terminal commands for syncing repositories
/*
* Example of how not to shoot your teammates
*/
// Get all nearby ships
List<Ship> nearby = this.getNearbyShips(arena);
// Loop over all the ships
for (int i = 0; i < nearby.size(); i++) {
Ship ship = nearby.get(i);
// Call the getTeam() method on any ship to get its team name
String myTeam = this.getTeam();
@vingkan
vingkan / readme.md
Last active July 24, 2017 23:26
ESI CS Episode 08
@vingkan
vingkan / readme.md
Last active July 27, 2017 01:39
ESI CS Episode 09
@vingkan
vingkan / SampleStrategy.java
Last active September 3, 2017 01:00
Battleships: Sample Student Strategy
@Override
public void doTurn(Arena arena) {
//Fill in strategy here
this.move(arena, Direction.NORTH);
List<Ship> nearby = this.getNearbyShips(arena);
for (int i = 0; i < nearby.size(); i++)
{
Ship unknown = nearby.get(i);
boolean isOnMyTeam = this.isSameTeamAs(unknown);
if (isOnMyTeam) {
@vingkan
vingkan / MinHealthSearch.java
Last active September 3, 2017 01:21
Battleships: Searching for an enemy ship with the lowest health to fire at.
@Override
public void doTurn(Arena arena) {
// Fill in your strategy here
int minHealth = 100;
this.move(arena, Direction.EAST);
Ship target = null;
List<Ship> nearby = this.getNearbyShips(arena);
for (int i = 0; i < nearby.size(); i++) {
Ship ship = nearby.get(i);
String myTeam = this.getTeam();
@vingkan
vingkan / hawklinkscraper.js
Created September 12, 2017 00:49
Scrape emails from HawkLink roster page.
var container = document.querySelector('[role="main"]').children[0].children[3].children[0].children[1].children[0];
var boxes = Array.from(container.children);
var results = [];
getEmailByBoxIndex({
container: container,
results: results,
boxes: boxes,
index: 0,
callback: printResults
});