Skip to content

Instantly share code, notes, and snippets.

View mortenjohs's full-sized avatar

Morten Johannes Ervik mortenjohs

  • International Agency for Research on Cancer
  • Lyon, France
View GitHub Profile
@mortenjohs
mortenjohs / extract.sh
Created November 16, 2022 09:39
Extract all zip files in folder into folders with the same name as zip files...
for i in *.zip; do unzip "$i" -d "${i%%.zip}"; done
@mortenjohs
mortenjohs / analyzer.rb
Created February 14, 2014 11:05
A small analyser of board game geek user stats.
require 'open-uri'
require 'nokogiri'
require 'pp'
require 'json'
def load_game id, refresh = false
filename = "./cache/#{id}.xml"
unless File.exist?(filename)
url = "http://www.boardgamegeek.com/xmlapi/boardgame/#{id}?stats=1"
file = File.open(filename,"w") do |f|
https://api.instagram.com/oauth/authorize/?client_id=[clientID]&redirect_uri=[redirectURI]&response_type=code&scope=relationships
client = Instagram.client
my_followers = client.user_followed_by.map(&:id)
client.user_follows.each do |u|
unless my_followers.include?(u.id)
response = unfollow(u.id, ACCESS_TOKEN)
body = JSON.parse(response.raw_body)
if body["meta"]["code"] == 400
puts "Did not unfollow #{u.username} (#{u.id}) -- #{body["meta"]["error_message"]}."
else
def unfollow id, access_token
host = 'api.instagram.com'
path = "/v1/users/#{id}/relationship?access_token=#{access_token}"
request = HTTPI::Request.new
request.url = "https://#{host}#{path}"
request.body = { action: "unfollow"}
HTTPI.post(request)
end
@mortenjohs
mortenjohs / videocalc.js
Created October 20, 2013 21:03
Add overall lesson timing to video listings on Coursera
function pad2(number){
if (number<10) {
return "0" + parseInt(number);
} else {
return parseInt(number);
}
}
var sectionList = $(".course-item-list-section-list"),
headerList = $(".course-item-list-header"),
@mortenjohs
mortenjohs / root-certs-rvm.sh
Created February 26, 2013 16:14
Ruby, rvm, and root certificates
mkdir $rvm_path/usr/ssl
cd $rvm_path/usr/ssl
curl -O http://curl.haxx.se/ca/cacert.pem # download certificates
mv cacert.pem cert.pem # move them in place
touch ~/.bashrc # create .bashrc if it does not exist
echo 'export SSL_CERT_FILE=~/.rvm/usr/ssl/cert.pem' >> ~/.bashrc # add key to environment
source ~/.bashrc # or close your consoles
@mortenjohs
mortenjohs / index.html
Last active December 12, 2015 08:18
D3 Map Projections Morphing
<!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<style>
.background {
fill: none;
pointer-events: all;
}
@mortenjohs
mortenjohs / index.html
Last active December 12, 2015 07:49
D3 Morphing Map Projections
<!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
<style>
.background {
fill: #a4bac7;
}
# parameters
k = 7
number_of_points = 10000
delta = 0.001
plot_on = false
require './k-means.rb'
points = []
number_of_points.times do