Skip to content

Instantly share code, notes, and snippets.

View eldritchideen's full-sized avatar

Steven Cook eldritchideen

  • Amazon Web Services
  • Australia
View GitHub Profile
@eldritchideen
eldritchideen / gist:87d33626bd85ebefbf24
Last active August 29, 2015 14:23
Get current list of shares making new highs
defmodule Stocks do
def get_new_highs do
HTTPoison.start
resp = HTTPoison.get!("http://www.smh.com.au/business/markets/52-week-highs?page=-1",[], [proxy: "http://proxy.cat.com:80"])
data = Floki.find(resp.body, "#content section table tbody tr th a")
Enum.map(data, fn({_,_,[code]}) -> code end)
end
end

Sample Project

Starting from:

lein new foo
cd foo

Say I have a random JAR file that is not available in any repository:

touch README.md

from zipline.algorithm import TradingAlgorithm
from zipline.transforms import MovingAverage
from zipline.utils.factory import load_from_yahoo
from zipline.finance.slippage import FixedSlippage
from zipline.finance.commission import PerShare
from datetime import datetime
import matplotlib.pyplot as plt
class DualMovingAverage(TradingAlgorithm):
@eldritchideen
eldritchideen / gist:b8edcea93ced80b03f53
Created January 31, 2015 00:33
Moving Average in Clojure
(defn average [coll]
(/ (reduce + coll)
(count coll)))
(defn ma [period coll]
(lazy-cat (repeat (dec period) nil)
(map average (partition period 1 coll))))
@eldritchideen
eldritchideen / gist:89b9ba06457b568f0d1a
Last active June 25, 2023 01:04
Very simple actor implementation with core.async
(ns scratch.core
(:require [clojure.core.async :as async :refer [go-loop <! chan <!! >! >!!]])
(:gen-class))
(defn make-actor
"Creates actor of specific name" [name]
(let [in (chan 10)]
(go-loop [[msg-type sender msg-body :as data] (<! in)]
(when data
(println (str "Actor " name " got message " msg-type
@eldritchideen
eldritchideen / gist:336fc3b823d2d0b89a13
Last active August 29, 2015 14:05
Getting points out of a DXF file
import dxfgrabber
dxf = dxfgrabber.readfile('surface0.dxf')
all_surface_entities = [entity for entity in dxf.entities if entity.layer == '0']
all_progress_line_entities = [entity for entity in dxf.entities if entity.layer == 'Progress Line']
f = open('surface_points.csv', 'w')
# List of Point objects
for p in all_surface_entities:
@eldritchideen
eldritchideen / gist:556bf5ea2091d59923ff
Created August 15, 2014 00:03
Some Pandas Share price stuff
from pandas import *
import pandas.io.data as web
import datetime
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2014, 8, 15)
# Get daily price data
ctx = web.DataReader('ctx.ax', 'yahoo', start, end)
@eldritchideen
eldritchideen / project.clj
Last active April 2, 2024 16:00
Web scraping in Clojure with Jsoup
(ns scraping.core
(:gen-class)
(:import (org.jsoup Jsoup)
(org.jsoup.select Elements)
(org.jsoup.nodes Element)))
(def URL "http://www.smh.com.au/business/markets/52-week-highs?page=-1")
(defn get-page []
(.get (Jsoup/connect URL)))
@eldritchideen
eldritchideen / gist:ef9295ff6c2f6aeca24e
Last active July 20, 2017 04:46
Web scraping in Scala with Jsoup
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import scala.collection.JavaConversions._
System.setProperty("http.proxyHost", "xxx.xxx.xxx")
val doc = Jsoup.connect("http://www.smh.com.au/business/markets/52-week-highs?page=-1").get()
//doc.body()
val elems = doc.select("#content > section > table > tbody > tr > th > a")
val foo = for ( e <- elems) yield e.text

This is my recommended path for learning Haskell.

Something to keep in mind: don't sweat the stuff you don't understand immediately. Just keep moving.

Primary course

http://www.seas.upenn.edu/~cis194/lectures.html Brent Yorgey's course is the best I've found so far and replaces both Yann Esposito's HF&H and the NICTA course. This course is particularly valuable as it will not only equip you to write Haskell but also help you understand parser combinators.

Exercises for practice