Skip to content

Instantly share code, notes, and snippets.

Magnus Hoff maghoff

Block or report user

Report or block maghoff

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
maghoff /
Last active Oct 4, 2019
Migrate all your repos (including wikis, _excluding_ issues) from Bitbucket to GitHub, converting hg to git in the process
#!/usr/bin/env bash
# Originally published on
# Copyright (c) 2019 Magnus Hovland Hoff
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
extern crate numtoa;
real 0m1.080s
user 0m0.684s
sys 0m0.392s
fn one() {
let mut i: i32 = 0;
while i < 10000000 {
maghoff /
Created Nov 2, 2015
Threads and scoping in rust
use std::thread;
fn greet(peeps: &str) {
println!("Hello, {}", peeps);
fn indirect(peeps: &str) {
// In this case, `peeps` outlives the thread, but Rust does not
maghoff / tictactoe.cpp
Created Nov 25, 2014
An AI for tic-tac-toe
View tictactoe.cpp
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <random>
constexpr int pow3(int n) {
if (n == 0) return 1;
else return 3 * pow3(n-1);
maghoff /
Created Nov 22, 2014
A perfect and pessimistic AI for tic-tac-toe
extern crate core;
use std::io;
use std::rand;
use std::rand::distributions::{IndependentSample, Range};
enum Field {
maghoff /
Last active Aug 29, 2015
An AI for tic-tac-toe
# Python 3!
import random
def show(board):
print('|%s|' % board[0:3])
print('|%s|' % board[3:6])
print('|%s|' % board[6:9])
View gist:5521751
#!/usr/bin/env python
import sys
words_file = "/usr/share/dict/words"
suffix = sys.argv[1]
candidates = set(w.strip()[:-len(suffix)] for w in open(words_file, 'rb') if w.strip().endswith(suffix))
words = [w.strip() for w in open(words_file, 'rb') if w.strip() in candidates]
maghoff /
Created Oct 2, 2012
Timing-tester for #pragblom
CCS="gcc clang"
O_VARIANTS="-O0 -O2 -O3 -Os -O99"
SORTS="quick selection radix shell insertion bubble"
for CC in $CCS
You can’t perform that action at this time.