Skip to content

Instantly share code, notes, and snippets.

View clausd's full-sized avatar

Claus Dahl clausd

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / gist:e205a151e3b354a4d7f1
Created February 13, 2015 12:58
Hive OECD data fra EVM
// på http://www.evm.dk/arbejdsomraader/vaekst-og-konkurrenceevne/redegoerlse-om-vaekst-og-konkurrenceevne
// åben dev console
data = []
$.ajaxSetup({complete: function(something) {obj = JSON.parse(something.response); data.push(JSON.parse(obj.d);}})
// og nu fanger man alle data hent på siden, i data - de kan så jsonificers og gemmes elsewhere
@clausd
clausd / octavehowto
Created February 9, 2015 22:03
Octave properly on Mavericks
Homebrew is fine
but ALWAYS
brew install octave --with-docs
or no packages will install inside octave (if you don't need packages, never mind the docs)
that in turn requires tex
you can
brew install Caskroom/cask/mactex
which builds a text installer that you can then run
- or download a binary, prolly much faster
After that you should be pretty golden and packages should install
@clausd
clausd / gist:67825a3ff0b3567e5dbe
Created January 9, 2015 10:47
Ruby 1.8.7 på Mavericks, rails 2.3.* på mavericks
https://github.com/wayneeseguin/rvm/issues/1975#issuecomment-20223263 fixede
løste Error running requirements_osx_brew_libs_install openssl098
løsning på The requested url does not exist(22): 'http://production.cf.rubygems.org/rubygems/rubygems-2.0.15.tgz'
er
wget
mv
nu ka man installere de rigtige rubygems versioner også...
@clausd
clausd / limiter.js
Created September 26, 2014 10:30
Form submission management - Coderdojo
FORM_OPEN_DATE = "2014-03-14 08:00";
FORM_CLOSE_DATE = "2014-11-09 23:30";
RESPONSE_COUNT = "30";
/* Web tutorial: http://labnol.org/?p=20707 */
/* Initialize the form, setup time based triggers */
function Initialize() {
deleteTriggers_();
@clausd
clausd / clear cache
Created June 14, 2014 08:53
Fix run amok Mediaserver on Android that's depleting data quota and battery
We're sorry to hear that you're experiencing problems with your data usage on your Nexus 5 device after updating to the latest Android version.
Troubleshooting for Nexus 5
To try and resolve the issue at hand, I have some troubleshooting steps I would like you to try:
Conduct a forced shut off by holding Power button and shutting phone down and restarting the device
Then, try clearing the cache partition. Here's how:
Hold power button for 2 seconds and select 'Power Off'
Press and hold the Volume Up and the Volume Down and Power keys at the same time for about 10 seconds.
An image of an Android lying on its back will appear.
Press the Volume Down key twice until "Recovery mode" appears on the screen.