This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Linear func for varying theta0 and theta1 | |
h <- function(x, h0, h1){ | |
return (h0 + h1*x) | |
} | |
# Cost function for fitting data | |
J <- function(h0, h1, m, d) { | |
y = seq() | |
for (i in seq(m)) { | |
y[i] = (h(d[i,1], h0, h1) - d[i,2])^2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parse_pri(digits): | |
if isinstance(digits, str): | |
if not digits.isdigit(): | |
raise ValueError("String is not digits") | |
else: | |
digits = int(digits) | |
if not isinstance(digits, int): | |
raise ValueError("Could not convert digit value. Must be int or str") | |
return (digits/8, digits%8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Installing graphite dependencies | |
apt-get install -y python2.6 python-pip python-cairo python-django python-django-tagging | |
apt-get install -y libapache2-mod-wsgi python-twisted python-memcache python-pysqlite2 python-simplejson | |
pip install whisper | |
pip install carbon | |
pip install graphite-web | |
# Setup a vhost by grabbing the example the graphite team released on their repo. | |
# In this file, you'll provide the url used to access to your Graphite dashboard | |
wget https://raw.github.com/tmm1/graphite/master/examples/example-graphite-vhost.conf -O /etc/apache2/sites-available/graphite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A naive dns server with a Redis backend | |
# now with added resolution if not in redis! | |
# -Neil | |
# Set keys in Redis you want to be authoritative for (set google.com. 127.0.0.1) | |
# Tip: Use Redis's ttl functions to have temporary names | |
# Currently only does A records, feel free to fix that | |
# | |
# Licensed under the PSF License | |
# Thanks to: http://code.activestate.com/recipes/491264-mini-fake-dns-server/ | |
# Author forked from: @Kaerast <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.BlockingQueue | |
import java.util.concurrent.LinkedBlockingQueue | |
import java.util.concurrent.TimeUnit | |
class MaxLeaseRetriesException(message:String = null, cause:Throwable = null) extends Exception(message, cause) | |
class ConnectionPool[R](maxSize:Int, timeout:Int = 1000, unit: TimeUnit = TimeUnit.MILLISECONDS) { | |
val q: BlockingQueue[R] = new LinkedBlockingQueue[R](maxSize) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import BeautifulSoup | |
html = requests.get("http://en.wikipedia.org/wiki/Python_(programming_language)").content | |
soup = BeautifulSoup.BeautifulSoup(html) | |
a_tags = soup.findAll("a") | |
links = [tag['href'] for tag in a_tags if tag.has_key('href') and tag['href'] is not None] | |
img_tags = soup.findAll("img") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import struct | |
import Queue | |
class QueueItem(object): | |
def __init__(self, msg_id, data, removed=False): | |
self.msg_id = msg_id | |
self.data = data | |
self.removed = removed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class verywrong(`a b`: Int, a: Int) | |
defined class verywrong | |
scala> verywrong(1, 2) | |
res0: verywrong = verywrong(1,1) |