Skip to content

Instantly share code, notes, and snippets.

@maghoff
maghoff / escape-bitbucket.sh
Last active April 25, 2021 18:36
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 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
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 November 2, 2015 18:38
Threads and scoping in rust
#![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 November 25, 2014 20:59
An AI for tic-tac-toe
#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 November 22, 2014 12:32
A perfect and pessimistic AI for tic-tac-toe
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 August 29, 2015 14:10
An AI for tic-tac-toe
# Python 3!
import random
def show(board):
print('+---+')
print('|%s|' % board[0:3])
print('|%s|' % board[3:6])
print('|%s|' % board[6:9])
print('+---+')
#!/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 October 2, 2012 11:47
Timing-tester for #pragblom
#!/bin/bash
CCS="gcc clang"
O_VARIANTS="-O0 -O2 -O3 -Os -O99"
SORTS="quick selection radix shell insertion bubble"
for CC in $CCS
do