Skip to content

Instantly share code, notes, and snippets.

View rafiamafia's full-sized avatar

Rafia Qutab rafiamafia

  • NASA Jet Propulsion Laboratory
  • Los Angeles, CA
View GitHub Profile
@rafiamafia
rafiamafia / ttt.rb
Created September 14, 2012 16:01 — forked from JoshCheek/ttt.rb
Tic Tac Toe - procedural with few abstractions, ~110 loc
UNMARKED = ' '
def board_to_s board
board.each_slice(3).map { |a, b, c| " #{a} | #{b} | #{c} " }.join("\n---|---|---\n")
end
def display board, after_board = nil
puts board_to_s board
puts after_board if after_board
end
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Blue Component</key>
<real>0.19370138645172119</real>
<key>Green Component</key>
<real>0.15575926005840302</real>
@rafiamafia
rafiamafia / ruby_conf_2014.md
Last active August 29, 2015 14:09
Ruby Conf San Diego 2014

#Day 1

Matz Keynote

Static Type vs. Dynamic Type.

  • Static Typing is against DRY.
  • Soft typing:
    • Type is represented by set of methods e.g name and # of arguments
    • Class (as set of methods)
@rafiamafia
rafiamafia / media_engineering_take_home.md
Last active April 25, 2019 19:35
Take home assignment for Fullscreen software engineering candidates.

Welcome to California

California is famous not only for its booming tech economy, controversial film industry, and yearlong summers, but due to its position on both the Pacific and North America plates, it experiences approximately 10,000 earthquakes each year. U.S. Geological Survey (USGS) provides near real time data and information and earth observations so that policy makers and the public have the understanding they need to enhance precedence, response and resilience.

You can find data of all earthquakes for the past 30 days here

Using the CSV above, write a Ruby program to find the first 10 cities and states with an earthquake that was felt in Los Angeles in a given date range. For the sake of over simplicity, let's assume a linear relationship between the magnitude of an earthquake and the distance it travels before it can be felt. Let's assume a magnitude-5 earthquake can be felt at up to a distance of 500 miles, ma

# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
@rafiamafia
rafiamafia / PyLinkedList.py
Created February 20, 2018 01:45
Python3 Linked List implementation
class Node:
def __init__(self, data, nextNode=None):
self.data = data
self.next = nextNode
def __str__ (self):
return str(self.data)
class PyLinkedList:
def __init__(self):
@rafiamafia
rafiamafia / PyStack.py
Created February 21, 2018 02:50
Stack implementation in Python
class PyStack():
def __init__(self):
self._items = []
def push(self, item):
self._items.append(item)
def pop(self):
if not self.isEmpty():
return self._items.pop()
@rafiamafia
rafiamafia / PyBinarySearchTree.py
Last active June 17, 2018 19:28
Python Binary Search Tree Implementation
class Node:
def __init__(self, data):
self.data = data
self.left = None
self.right = None
# To allow duplicates we can store extra information i.e count
# to optimize memory and make search, insert, delete easier
#self.count = 1
def insert(self, data):
class Node:
def __init__(self, data):
self.data = data
self.parent = self
self.rank = 0
class DisjointSet:
def __init__(self):
self.map = {}
@rafiamafia
rafiamafia / PyTrie.py
Last active August 15, 2018 16:49
A Trie class in python
class TrieNode:
def __init__(self):
self.children = dict()
self.end_of_word = False
def leafNode(self):
return self.end_of_word
def freeNode(self):
return not any(self.children)