Skip to content

Instantly share code, notes, and snippets.

View msanatan's full-sized avatar
🏠
Working from home

Marcus Sanatan msanatan

🏠
Working from home
View GitHub Profile
@msanatan
msanatan / namis_scraper.py
Last active August 29, 2015 14:04
Scraper for wholesale fish market prices in Trinidad and Tobago
from lxml import html
import requests
import time
date = time.strftime('%d-%m-%Y')
output = ''
try:
page = requests.get('http://www.namistt.com/')
except requests.exceptions.RequestException as e:
@msanatan
msanatan / sieve_of_eratosthenes.js
Last active August 29, 2015 14:09
Sieve of Eratosthenes
var populateSieve = function(N) {
'use strict';
var arr = [N+1];
arr[0] = false;
arr[1] = false;
for (var i = 2; i <= N; i++) {
arr[i] = true;
}
return arr;
};
@msanatan
msanatan / ttconnect_ministry_scraper.py
Last active August 29, 2015 14:15
Scraper for ttconnect Government Ministry page
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''A web scraper for the Government of Trindad and Tobago's Ministry data. The
main link: http://www.ttconnect.gov.tt/'''
from lxml import html
import requests
import json
from collections import OrderedDict
from argparse import ArgumentParser
@msanatan
msanatan / fsm.coffee
Last active August 29, 2015 14:17
FSM implementation in CoffeeScript
class Transition
constructor: (@currentState, @input, @nextState) ->
match: (currentState, input) ->
return @currentState is currentState and @input is input
getNextState: ->
return @nextState
@msanatan
msanatan / solar-system.coffee
Created September 25, 2015 03:23
HTML5 solar system - definitely not drawn to scale lol. Orbit speeds are roughly to scale :)
class Planet
constructor: (@radius, @colour, @baseX, @baseY, @orbitSpeed) ->
@x = @baseX
@y = @baseY
@startTime = Date.now()
@theta = 0
update: (sun) ->
newTime = Date.now()
@msanatan
msanatan / coin-sprite-sheet.png
Last active March 26, 2016 23:05
Animate a coin sprite with ES2015
coin-sprite-sheet.png
@msanatan
msanatan / game_tictactoe.py
Last active September 10, 2017 04:24
Tic Tac Toe with Pygame
import pygame
import sys
import os
# SDL is the library which Pygame uses
# We use SDL to put the game window at the screen's centre
os.environ['SDL_VIDEO_CENTERED'] = '1'
SCREEN_SIZE = (800, 640)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
@msanatan
msanatan / Breakout.js
Last active November 7, 2017 04:12
Breakout in ES2015
import Phaser from 'phaser';
class Game extends Phaser.Game {
constructor (width, height, mode, domElement='content', arg=null) {
super(width, height, mode, domElement, arg);
this.state.add('Game', GameState, true);
}
}
class GameState extends Phaser.State {
@msanatan
msanatan / Cyclic.hs
Created December 12, 2013 18:44
Simple way to check if a directed graph is cyclic in Haskell. Essentially it's a stripped down version of the Arthur B Kahn topological sorting algorithm. Uses the Functional Graph Library (http://hackage.haskell.org/package/fgl) for graph representation.
module Cyclic
(leafNode,
hasLeaf,
delLeaf,
cyclic
) where
import Data.Graph.Inductive
{- Topological sorting involves removing nodes from the graph into a list to
@msanatan
msanatan / pong.py
Created June 1, 2017 04:57
Pygame Pong - not the way I would naturally code this, to be used in a class for teaching
import pygame
import sys
import random
SCREEN_SIZE = WIDTH, HEIGHT = (800, 640)
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (50, 255, 50)
BLUE = (50, 50, 255)
SCORE_LIMIT = 5