View index.pug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- var baseURL = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/544318/'; | |
- var info = [{ | |
- city: 'Venice', | |
- country: 'Italy', | |
- population: '260,060', | |
- founded: '697', | |
- image: baseURL + 'venice.jpg', | |
- emblem: baseURL + 'italian-emblem.svg'; | |
- }, { |
View main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Rectangle { | |
width: u32, | |
height: u32, | |
} | |
impl Rectangle { | |
fn area(&self) -> u32 { // this is a method when inside an `impl` | |
self.width * self.height |
View main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Rectangle { | |
width: u32, | |
height: u32, | |
} | |
fn main() { | |
let rect1 = Rectangle { width: 30, height: 50 }; | |
let rect2 = Rectangle { width: 42, height: 42 }; | |
println!( |
View main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// code source: | |
// https://doc.rust-lang.org/rust-by-example/primitives/tuples.html | |
// rust-by-example | |
// Tuples can be used as function arguments and as return values | |
fn reverse(pair: (i32, bool)) -> (bool, i32) { | |
// `let` can be used to bind the members of a tuple to variables | |
let (integer, boolean) = pair; |
View main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(unused_variables)] | |
/* | |
ownership rules | |
A. each value has a var thats called its `owner` | |
B. only one `owner` per value | |
C. when the `owner` goes out of scope, its value is dropped | |
View demo.wat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(module | |
;; Import the required fd_write WASI function which will write the given io vectors to stdout | |
;; The function signature for fd_write is: | |
;; (File Descriptor, *iovs, iovs_len, nwritten) -> Returns number of bytes written | |
(import "wasi_unstable" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32))) | |
(memory 1) | |
(export "memory" (memory 0)) | |
;; Write 'hello world\n' to memory at an offset of 8 bytes |
View main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::env; | |
use std::fs; | |
use std::io::{Read, Write}; | |
fn process(input_fname: &str, output_fname: &str) -> Result<(), String> { | |
let mut input_file = | |
fs::File::open(input_fname).map_err(|err| format!("error opening input: {}", err))?; | |
let mut contents = Vec::new(); | |
input_file | |
.read_to_end(&mut contents) |
View main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::env; | |
use std::fs; | |
use std::io::{Read, Write}; | |
fn process(input_fname: &str, output_fname: &str) -> Result<(), String> { | |
let mut input_file = | |
fs::File::open(input_fname).map_err(|err| format!("error opening input: {}", err))?; | |
let mut contents = Vec::new(); | |
input_file | |
.read_to_end(&mut contents) |
View demo.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <errno.h> | |
int main(int argc, char **argv) { | |
int n, m; | |
char buf[BUFSIZ]; |
View main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
another_function(5, 6); | |
let x = 5; | |
let y = { | |
let x = 3; | |
x + 2 // no semi-colon is used for an expression | |
}; |
NewerOlder