Skip to content

Instantly share code, notes, and snippets.

View clausd's full-sized avatar

Claus Dahl clausd

View GitHub Profile
@clausd
clausd / HOWTO
Created May 29, 2015 19:19
Deploy sinatra apps quickly on Site 5
Getting Ruby above 1.8.7 up and running on Site 5
Start with http://kb.site5.com/ruby-on-rails/select-a-version-of-ruby-for-your-hosting-account/ is a little off
For some reason - my .bashrc is not picked up - but I can just
source .bashrc
and that works then
Check your Ruby is 1.9 something or 2.0 something
Now you need to install bundler AFTER doing that
verify your bundle command is now in ~/ruby/gems
@clausd
clausd / skrab.rb
Created June 19, 2015 15:48
Valgskrab
require 'mechanize'
require 'logger'
require 'json'
ROOT = "http://www.kmdvalg.dk/main"
def get_agent
agent = Mechanize.new
agent.log = Logger.new "mech.log"
agent.user_agent_alias = 'Mac Safari'
@clausd
clausd / boston.json
Last active September 16, 2015 11:04 — forked from pprett/boston.json
Decision Tree Viewer (D3 and Sklearn)
{"error": 42716.2954, "samples": 506, "value": [22.532806324110698], "label": "RM <= 6.94", "type": "split", "children": [{"error": 17317.3210, "samples": 430, "value": [19.93372093023257], "label": "LSTAT <= 14.40", "type": "split", "children": [{"error": 6632.2175, "samples": 255, "value": [23.349803921568636], "label": "DIS <= 1.38", "type": "split", "children": [{"error": 390.7280, "samples": 5, "value": [45.58], "label": "CRIM <= 10.59", "type": "split", "children": [{"error": 0.0000, "samples": 4, "value": [50.0], "label": "Leaf - 4", "type": "leaf"}, {"error": 0.0000, "samples": 1, "value": [27.9], "label": "Leaf - 5", "type": "leaf"}]}, {"error": 3721.1632, "samples": 250, "value": [22.90520000000001], "label": "RM <= 6.54", "type": "split", "children": [{"error": 1636.0675, "samples": 195, "value": [21.629743589743576], "label": "LSTAT <= 7.57", "type": "split", "children": [{"error": 129.6307, "samples": 43, "value": [23.969767441860473], "label": "TAX <= 222.50", "type": "split", "children": [{"err
@clausd
clausd / collatz.rb
Last active November 4, 2015 14:10
Euler shit
c = {}
def cached_collatz(n,c)
c[1] = [1]
i = n
s = []
while c[i].nil?
s.push(i)
i = (i % 2 == 0 ? i/2 : 3*i+1)
end
while s.count > 0
@clausd
clausd / turing.rb
Last active February 15, 2018 12:20
Turing machines in ruby arithmetic
# Let's implement turing machines in ruby arithemtic
# we want to encode tape, state and position in a single integer and - given a turing machine - write
# a function that emulates the turing machine.
# We limit our selves to simple machines - 100 states tops, 100000 positions on the tape
NSTATES = 100
NPOSITIONS=100000
# check for zero
def d(x)
@clausd
clausd / exsql.py
Last active March 2, 2016 08:06
Excel to Mysql
import argparse
import pandas as pd
import mysql.connector
from sqlalchemy import create_engine
from string import Template
import os
import argparse
parser = argparse.ArgumentParser()
@clausd
clausd / build_it.rb
Created March 3, 2016 14:28
Just want to expand some values into static files - not a "blog engine". This is already overkilll
#!/usr/bin/ruby
require 'erb'
require 'json'
require 'yaml'
require 'fileutils'
@from = ARGV.shift || 'files'
@to = ARGV.shift || 'dist'
# definitions
class IntrospectBinding
attr_accessor :binding, :evals
def initialize(binding)
@binding = binding
@evals = []
end
def eval(string, filename = '', lineno = 0)
@clausd
clausd / mixpanel.py
Last active September 7, 2016 10:12
#! /usr/bin/env python
#
# Mixpanel, Inc. -- http://mixpanel.com/
#
# Python API client library to consume mixpanel.com analytics data.
#
# Copyright 2010-2013 Mixpanel, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@clausd
clausd / watch.py
Created December 20, 2016 13:26
How to do LDA in python (for Morten)
import numpy as np
import pandas as pd
import lda
import lda.datasets
from sklearn.feature_extraction.text import CountVectorizer
def load_questions():
sheet = pd.read_excel('android_watch.xlsx')
Qs = sheet['Question']