Skip to content

Instantly share code, notes, and snippets.

scala> case class verywrong(`a b`: Int, a: Int)
defined class verywrong
scala> verywrong(1, 2)
res0: verywrong = verywrong(1,1)
@theanti9
theanti9 / DurableQueue.py
Created December 31, 2014 05:29
A Durable (non thread safe) Queue class backed by a commit log.
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
@theanti9
theanti9 / ConnectionPool.scala
Created July 31, 2014 06:51
A simple class for managing a connection pool.
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)
# 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 <alice@kaerast.info>
# 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
@theanti9
theanti9 / parser.py
Last active August 29, 2015 13:56
Get the Facility and Severity numbers out of the Priority value in syslog.
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)
@theanti9
theanti9 / cost_func.r
Created April 23, 2013 03:52
Create fit lines for data plots in R
# 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