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
maghoff / escape-bitbucket.sh
Last active Oct 4, 2019
Migrate all your repos (including wikis, _excluding_ issues) from Bitbucket to GitHub, converting hg to git in the process
View escape-bitbucket.sh
#!/usr/bin/env bash
# Originally published on https://magnushoff.com/blog/kick-the-bitbucket/
# 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
View fizzbuzz.rs
extern crate numtoa;
/*
real 0m1.080s
user 0m0.684s
sys 0m0.392s
*/
fn one() {
let mut i: i32 = 0;
while i < 10000000 {
@maghoff
maghoff / main.rs
Created Nov 2, 2015
Threads and scoping in rust
View main.rs
#![feature(scoped)]
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
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
maghoff / tictactoe.rs
Created Nov 22, 2014
A perfect and pessimistic AI for tic-tac-toe
View tictactoe.rs
extern crate core;
use std::io;
use std::rand;
use std::rand::distributions::{IndependentSample, Range};
#[deriving(PartialEq)]
enum Field {
N,
X,
O,
@maghoff
maghoff / tictactoe.py
Last active Aug 29, 2015
An AI for tic-tac-toe
View tictactoe.py
# Python 3!
import random
def show(board):
print('+---+')
print('|%s|' % board[0:3])
print('|%s|' % board[3:6])
print('|%s|' % board[6:9])
print('+---+')
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
maghoff / gather.sh
Created Oct 2, 2012
Timing-tester for #pragblom
View gather.sh
#!/bin/bash
CCS="gcc clang"
O_VARIANTS="-O0 -O2 -O3 -Os -O99"
SORTS="quick selection radix shell insertion bubble"
for CC in $CCS
do
You can’t perform that action at this time.