Skip to content

Instantly share code, notes, and snippets.

Avatar

∞ metazoan.icp ∞ μεταζωαn ∞ der0pa

View GitHub Profile
@der0pa
der0pa / index.pug
Last active Aug 29, 2021
Travel Gallery (Flexbox and CSS Animations/Transitions)
View index.pug
- 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';
- }, {
@der0pa
der0pa / main.rs
Created Jan 16, 2020
rectangles using 'struts' and 'impls'
View main.rs
#[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
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
// 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;
@der0pa
der0pa / main.rs
Last active Jan 10, 2020
notes of ownership
View main.rs
#![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
@der0pa
der0pa / demo.wat
Created Jan 7, 2020
wasm .wat file
View demo.wat
(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
@der0pa
der0pa / main.rs
Created Jan 7, 2020
rust version of oficial wasmtime tutorial
View main.rs
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
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)
@der0pa
der0pa / demo.c
Created Jan 7, 2020
from .c to .wasm that can run on wasmtime
View demo.c
#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
fn main() {
another_function(5, 6);
let x = 5;
let y = {
let x = 3;
x + 2 // no semi-colon is used for an expression
};