Skip to content

Instantly share code, notes, and snippets.

@moonhouse
moonhouse / pk_counter.rb
Created May 14, 2013 09:17
Lista antalet Facebook-kommentarer som innehåller en viss sträng.
# encoding: UTF-8
require 'json'
require 'open-uri'
# 2013-05-14, inspirerad av https://www.facebook.com/fjohansson/posts/10151388440332181
def get_messages data, offset = 0
comments = []
data.each do |comment|
comments.push comment["message"]
#encoding: utf-8
require 'csv'
require 'geocoder'
CSV.open("responses-geocoded.csv", "wb") do |csv|
arr_of_arrs = CSV.read("responses.csv")
output = {}
arr_of_arrs.each_with_index do |row, i|
next if i > 22
#encoding: utf-8
require 'csv'
require 'json'
arr_of_arrs = CSV.read("Survey-responses (2).csv")
output = {}
arr_of_arrs.each_with_index do |row, i|
next if i == 0
lat = row[14].to_f
@moonhouse
moonhouse / download_air_quality_data.rb
Created May 4, 2013 19:34
Load data from HTML table into CSV file #fajkhack 2013
#encoding: utf-8
require 'mechanize'
require 'csv'
uri = 'http://www3.ivl.se/db/plsql/dvst_pm25_st$b1.querylist'
uri2 = 'http://www3.ivl.se/db/plsql/dvst_pm10_st$b1.actionquery'
agent = Mechanize.new
page = agent.get uri
page_no = 0
@moonhouse
moonhouse / dltest.rb
Created April 28, 2013 21:48
Logging downloading attempts of large file
require 'net/http'
require 'digest/md5'
require 'sqlite3'
require 'date'
uri = URI('http://www.lysator.liu.se/~dp/myfile')
md5 = '98a4dda5aebe0675d864cd10c5fae75a'
# CREATE TABLE results (datetime at, boolean ok, integer bodysize, text errormessage);
@moonhouse
moonhouse / payson.php
Created January 3, 2013 00:04
WIP Payson payment gateway
<?php
/**
* @package Marketpress_Payment_Payson
* @version 0.2
*/
/*
Plugin Name: Payson for Marketpress
Plugin URI: http://dpg.se/wordpress/payson
Description: Enables purchases via Payson in Marketpress.
Author: David Hall
@moonhouse
moonhouse / diarium.rb
Created December 20, 2012 22:13
Skapa RSS för dagens diarium från en av länsstyrelserna
# encoding: UTF-8
require 'mechanize'
require 'builder'
@agent = Mechanize.new
def get_list(diary_id)
page = @agent.get("http://diarium.lansstyrelsen.se/default.aspx")
form = page.form('aspnetForm')
@moonhouse
moonhouse / geo_conv.rb
Created May 5, 2012 14:15
Convert RT90 to WGS84
def convert_rt90_to_wgs84(geopos)
# from http://mellifica.se/geodesi/gausskruger.js
geopos=geopos.first
x = geopos['x'].to_i
y = geopos['y'].to_i
axis = 6378137.0 # GRS 80.
flattening = 1.0 / 298.257222101 # GRS 80.
central_meridian = 15.0 + 48.0/60.0 + 22.624306/3600.0
@moonhouse
moonhouse / list_blogs.rb
Created December 1, 2011 10:54
Retrieve feed information from WPMU server given a dump of the page /wp-admin/my-sites.php in blogdump.html
# encoding: UTF-8
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('blogdump.html'))
doc.xpath('//select[@name="primary_blog"]/option').each do |link|
blog_url = link.content
begin
rss = Nokogiri::XML(open("#{blog_url}/feed/"))
@moonhouse
moonhouse / report-jobs.rb
Created November 16, 2011 11:37
Parse Jenkins builds and HTTP POST summaries.
require 'nokogiri'
require 'httparty'
def is_build_no(dir_name)
(dir_name =~ /\/\d*$/) != nil
end
def is_build_time(dir_name)
# Match paths ending with timestamps such as 2011-10-17_15-06-32
(dir_name =~ /\/\d*-\d*-\d*_\d*-\d*-\d*$/) != nil