Skip to content

Instantly share code, notes, and snippets.

@anka-213
anka-213 / Primes.rs
Created April 19, 2016 21:07 — forked from anonymous/playground.rs
Shared via Rust Playground
#![allow(dead_code, unused_variables)]
struct PrimeList {
primes: Vec<i64>,
}
/// Basically the same as
/// self.primes.iter().cloned().chain(self) on a PrimeList
struct PrimeIter<'a> {
primes: &'a mut PrimeList,
@anka-213
anka-213 / linked_list.rs
Last active April 19, 2016 21:14 — forked from anonymous/playground.rs
Shared via Rust Playground
//#![allow(dead_code)]
use std::iter::FromIterator;
// Example of linked lists -- Comes from stackoverflow
enum List { Nil, Cons{value: i32, next: Box<List>}}
fn main() {
let v = vec![1, 5, 3, 8, 12, 56, 1230, 2, 1];
@anka-213
anka-213 / sudoku_solver.hs
Last active April 27, 2016 06:15
An attempt at a sudoku solver using bitfields
--let attempt2bitmap (x,y,n) = ((9*x+n)*9^4, (9*y+n)*9^2, 9*x+y)
--let allAttempts = [bit row .|. bit col .|. bit pos | x <- [0..8], y <- [0..8], n <- [0..8], let (row, col, pos) = attempt2bitmap (x,y,n)] :: [Integer]
--let attempt2bitmap x y n = bit (9*x + n) .|. bit (9*y + n + 9^2) .|. bit (9*boxOf x y + n + n^4) .|. bit (9*x + y + 9^6) :: Integer
let attempt2bitnr x y n = [9*x + n, 9*y + n, 9*boxOf x y + n, 9*x + y] :: [Int]
let attempt2bitmap x y n = sum [ bit $ a + 9^2*i | (i,a) <- zip [0..] $ attempt2bitnr x y n] :: Integer
let matrix2bitmaps rows = [ attempt2bitmap x y (n-1) | (x, row) <- zip [0..] rows, (y, n) <- zip [0..] row, n /= 0]
let mapMatIdx f rows = [ f x y (n-1) | (x, row) <- zip [0..] rows, (y, n) <- zip [0..] row, n /= 0]
let matrix2tuples = mapMatIdx (,,)
@anka-213
anka-213 / mbox.rs
Last active May 12, 2016 22:37 — forked from anonymous/playground.rs
Shared via Rust Playground
// #![allow(dead_code)]
// #![allow(unused_variables)]
// #![allow(unused_mut)]
#![feature(question_mark)]
use std::sync::Mutex;
use std::sync::Arc;
use std::collections::VecDeque;
use std::thread;
use std::ops::Deref;
@anka-213
anka-213 / gc.rs
Last active May 12, 2016 22:44 — forked from anonymous/playground.rs
Shared via Rust Playground
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
struct Asdf(i32, Option<Gc<Asdf>>);
struct Gc<T>(*const T);
impl<T> Drop for Gc<T> {
fn drop(&mut self) {
@anka-213
anka-213 / playground.rs
Created May 12, 2016 22:44 — forked from anonymous/playground.rs
Shared via Rust Playground
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
struct Asdf(i32, Option<Gc<Asdf>>);
struct Gc<T>(*const T);
impl<T> Drop for Gc<T> {
fn drop(&mut self) {
// ==UserScript==
// @name BlockBlockAdBlock
// @namespace http://github.com/anka-213
// @version 0.1.1
// @description Block the BlockAdBlock script
// @author Andreas Källberg
// @match http://blockadblock.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
@anka-213
anka-213 / defer.rs
Created June 3, 2016 17:23 — forked from anonymous/playground.rs
Shared via Rust Playground
macro_rules! defer {
($x:expr) => {
let _x = {
struct Deferred<F: Fn()>(F);
impl<F: Fn()> Drop for Deferred<F> {
fn drop(&mut self) {
self.0();
}
}
@anka-213
anka-213 / reuse_buf.rs
Last active September 24, 2016 18:22 — forked from anonymous/playground.rs
(un)Safe reusable buffers
//#![feature(question_mark)]
use std::ops::Deref;
use std::ops::DerefMut;
#[derive(Debug, Default)]
struct ReuseBuf {
inner: Vec<u32>,
used: bool
}
@anka-213
anka-213 / playground.rs
Created September 27, 2016 00:46 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(unboxed_closures)]
#![feature(fn_traits)]
#[derive(Clone)]
struct Pr {
pat: i32 //, mat: Matcher<'a,'a>
}
type MState = i32;