Skip to content

Instantly share code, notes, and snippets.

View danslimmon's full-sized avatar

Dan Slimmon danslimmon

View GitHub Profile
@danslimmon
danslimmon / ui.R
Created October 11, 2013 13:50
Defines the browser part of my error tracking Shiny app.
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("PHP errors by time"),
sidebarPanel(
checkboxGroupInput("errors_shown", "Most common errors:", c(
"davidbowie.php:50"="lib/exosite/robot/davidbowie.php:50",
"heehaw.php:728"="inc/spoot/heehaw.php:728",
@danslimmon
danslimmon / gist:6925793
Created October 10, 2013 21:16
Should this not generate an event every 5 seconds with "foo.count", "foo.rate_1m", etc. fields?
input { stdin {} }
filter { metrics { meter => [ "foo" ] } }
output { stdout { debug => true } }
@danslimmon
danslimmon / cql_client.py
Last active March 7, 2018 04:07
Using Python's cql module, connect to a Cassandra server over SSL
from thrift.transport import TSSLSocket
from thrift.transport import TTransport
import cql
sock = TSSLSocket.TSSLSocket(host='cass.example.com', port=9160, ca_certs='/path/to/ca_certs.pem')
trans = TTransport.TFramedTransport(sock)
conn = cql.connect('cass.example.com', 9160, 'keyspace', user='username', password='password', transport=trans, cql_version='3.0.0')
4> [self() ! X || X <- [rhythm,music,'my girl']].
[rhythm,music,'my girl']
5> flush().
Shell got rhythm
Shell got music
Shell got 'my girl'
ok
@danslimmon
danslimmon / generate_db.rb
Created August 31, 2013 20:46
Goes through the HTML files in the directory /Users/dan/j-archive/html, which have come from http://www.j-archive.com/showgame.php?game_id=<NUMBER> and are called <NUMBER>.html, and parses out the questions, answers, categories, etc. Generates SQL which can be loaded into a SQLite database.
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
class Clue
attr_accessor :text, :answer, :value, :category, :round, :difficulty, :shownumber
end
def escape(text)
@danslimmon
danslimmon / cassandra.yaml
Created August 28, 2013 20:26
cassandra.yaml that causes the crash logged at https://gist.github.com/danslimmon/6370745 when trying to add client encryption. Posted on ServerFault: http://serverfault.com/questions/534614/cannot-bind-to-port-enabling-cassandra-client-encryption
cluster_name: 'cassandra-00'
num_tokens: 256
hinted_handoff_enabled: true
max_hint_window_in_ms: 10800000
hinted_handoff_throttle_in_kb: 1024
max_hints_delivery_threads: 2
authenticator: org.apache.cassandra.auth.PasswordAuthenticator
@danslimmon
danslimmon / bah.log
Created August 28, 2013 20:22
Cassandra error when attempting to start up with client_encryption: true. Posted on Serverfault: http://serverfault.com/questions/534614/cannot-bind-to-port-enabling-cassandra-client-encryption
INFO 20:12:11,648 Logging initialized
INFO 20:12:11,673 JVM vendor/version: Java HotSpot(TM) 64-Bit Server VM/1.7.0_25
INFO 20:12:11,675 Heap size: 1017380864/1018429440
INFO 20:12:11,675 Classpath: /usr/share/cassandra/lib/antlr-3.2.jar:/usr/share/cassandra/lib/avro-1.4.0-fixes.jar:/usr/share/cassandra/lib/avro-1.4.0-sources-fixes.jar:/usr/share/cassandra/lib/commons-cli-1.1.jar:/usr/share/cassandra/lib/commons-codec-1.2.jar:/usr/share/cassandra/lib/commons-lang-2.6.jar:/usr/share/cassandra/lib/compress-lzf-0.8.4.jar:/usr/share/cassandra/lib/concurrentlinkedhashmap-lru-1.3.jar:/usr/share/cassandra/lib/guava-13.0.1.jar:/usr/share/cassandra/lib/high-scale-lib-1.1.2.jar:/usr/share/cassandra/lib/jackson-core-asl-1.9.2.jar:/usr/share/cassandra/lib/jackson-mapper-asl-1.9.2.jar:/usr/share/cassandra/lib/jamm-0.2.5.jar:/usr/share/cassandra/lib/jbcrypt-0.3m.jar:/usr/share/cassandra/lib/jline-1.0.jar:/usr/share/cassandra/lib/json-simple-1.1.jar:/usr/share/cassandra/lib/libthrift-0.7.0.jar:/usr/share/cassandra/lib/l
danslimmon@cassandra-00:~$ cassandra-shuffle enable --thrift-host 192.168.129.11
Failed to enable shuffling on 192.168.176.204!
Failed to enable shuffling on 192.168.178.133!
@danslimmon
danslimmon / crappyshuffle.py
Created July 30, 2013 21:26
Sorting by a random comparison function is a crappy way to shuffle.
# Sort [1,2,3,4] with a cmp function that returns -1, 0, or 1 with equal probability.
# Do it 10^5 times.
h={1:0,2:0,3:0,4:0}
for i in range(99999):
a = sorted([1,2,3,4],
lambda a, b: random.sample([-1,0,1], 1)[0])
h[a[0]] += 1
h
# => {1: 60443, 2: 17374, 3: 10990, 4: 11192}
# The first element of `a` was `1` 60% of the time!
@danslimmon
danslimmon / logstash_postfix.conf
Last active July 30, 2018 21:32
My logstash config for postfix logs
filter {
# Capture all the generic syslog stuff and populate @timestamp
if [type] == "postfix" {
grok {
match => [ "message", "%{SYSLOGBASE} %{GREEDYDATA:_syslog_payload}" ]
singles => true
}
# Postfix pads single-digit numbers with spaces (WHYYYYY)
mutate { gsub => [ "timestamp", " ", " 0" ] }
date { match => [ "timestamp", "MMM dd HH:mm:ss"] }