Skip to content

Instantly share code, notes, and snippets.

@nebuta
nebuta / rust-0.11-pre-cookbook.md
Last active August 29, 2015 13:58
Rust cookbook

Rust Cookbook for Rubyists

These examples compile on rustc 0.11-pre-nightly (540c2a2 2014-04-04 01:01:51 -0700)

Array

// vector testing

// Vector is kind of complicated part of Rust, partly because it's also convolved with pointers ~, &.
@nebuta
nebuta / gcj_2009_qual_a.rs
Created April 5, 2014 19:28
Google Code Jam 2009 qual round: A. Alien Language
use std::io::BufferedReader;
use std::io::stdin;
// Google Code Jam: Qualification Round 2009, Problem A. Alien Language
//https://code.google.com/codejam/contest/90101/dashboard#s=p0
// Compiles on Rust 0.11-pre
// This uses unwrap() functions that can fail.
// This is okay for programming contest problems.
@nebuta
nebuta / split_and_to_i.rs
Created April 4, 2014 18:31
Rust stdin splitting and conversion to int
// Compiles on rustc 0.11-pre-nightly (540c2a2 2014-04-04 01:01:51 -0700)
use std::io::BufferedReader;
use std::io::stdin;
fn main(){
let mut stdin = BufferedReader::new(stdin());
let l = stdin.read_line();
match l {
Ok(ll) => {
@nebuta
nebuta / echo.rs
Created April 4, 2014 18:14
Rust echo example
// Compiles on rustc 0.11-pre-nightly (540c2a2 2014-04-04 01:01:51 -0700)
use std::io::BufferedReader;
use std::io::stdin;
fn main(){
let mut stdin = BufferedReader::new(stdin());
for line in stdin.lines() {
match line {
Ok(l) => print!("{}",l),
@nebuta
nebuta / tiff.rs
Last active August 29, 2015 13:57
Parsing TIFF files in Rust
// tiff.rs
// Compiles on rustc 0.10-pre (6eae7df 2014-03-20 15:01:47 -0700)
#[crate_id = "tiff"];
#[crate_type="bin"];
#[license = "MIT"];
#[desc = "TIFF reading example"];
//! TIFF reading library.
//! Supports multipage tiff files.
@nebuta
nebuta / gsl_ffi_test.rs
Last active August 29, 2015 13:57
Rust FFI test with GSL
// gsltest.rs
//
// Rust version clone of the example of GSL linear algebra at
// http://www.gnu.org/software/gsl/manual/html_node/Linear-Algebra-Examples.html
//
// Works with Rust 0.9.
//
// Command for compiling on Mac OSX. You need to have GSL installed:
// rustc gsltest.rs -L/opt/local/lib
@nebuta
nebuta / determinant.rs
Created March 21, 2014 20:25
Matrix determinant calculation by cofactor expansion by Rust
use std::int::pow;
use std::rand;
use std::rand::Rng;
struct Matrix {
p: ~[int],
height: uint,
width: uint
}
@nebuta
nebuta / delaunay-server.hs
Last active August 29, 2015 13:57
Delaunay triangulation that runs as a service
{-# LANGUAGE OverloadedStrings #-}
import Graphics.Triangulation.Delaunay
import Data.Vector.V2
import Data.Aeson
import Data.ByteString (ByteString)
import Data.Text.Lazy.Encoding (encodeUtf8)
import Data.Text.Lazy (Text)
import qualified Data.Text.Lazy as TL
@nebuta
nebuta / delaunay-fiji.py
Last active August 29, 2015 13:57
Data processing on Fiji using Jython and a remote server.
import httplib, urllib, marshal
def getVal(table, i):
x = table.getValue('X', i)
y = table.getValue('Y', i)
return [x, y]
def draw_triangles(imp, triangles):
ip = imp.getProcessor()
binwidth = 1
bin(x,width)=width*floor(x/width)
plot 'histdata.dat' using (bin($1,binwidth)):(1.0) smooth freq with boxes