Skip to content

Instantly share code, notes, and snippets.

@rylev
rylev / sort.ex
Created October 9, 2013 19:07
Sort Algorithms in Elixir
## Sort Algorithms in Elixir
# Selection Sort
defmodule Selection do
def sort(list) when is_list(list) do
do_selection(list, [])
end
def do_selection([head|[]], acc) do
@rylev
rylev / learn.md
Created March 5, 2019 10:50
How to Learn Rust

Learning Rust

The following is a list of resources for learning Rust as well as tips and tricks for learning the language faster.

Warning

Rust is not C or C++ so the way your accustomed to do things in those languages might not work in Rust. The best way to learn Rust is to embrace its best practices and see where that takes you.

The generally recommended path is to start by reading the books, and doing small coding exercises until the rules around borrow checking become intuitive. Once this happens, then you can expand to more real world projects. If you find yourself struggling hard with the borrow checker, seek help. It very well could be that you're trying to solve your problem in a way that goes against how Rust wants you to work.

@rylev
rylev / rust-in-large-organizations-notes.md
Last active February 2, 2023 10:08
Rust in Large Organizations Notes

Rust in Large Organizations

Initially taken by Niko Matsakis and lightly edited by Ryan Levick

Agenda

  • Introductions
  • Cargo inside large build systems
  • FFI
  • Foundations and financial support
@rylev
rylev / bubble.rs
Created December 6, 2014 14:20
Bubble Sort Written In Rust
fn bubble_sort(numbers: &Vec<i64>, compare_fn: |i64, i64| -> i64) -> Vec<i64> {
let mut temp;
let mut target = numbers.clone();
let length = numbers.len();
for _ in range(0, length) {
for j in range(0, length - 1) {
if compare_fn(target[j], target[j+1]) > 0 {
temp = target[j+1];
target[j+1] = target[j];
defmodule User do
defstruct firstname: "Ryan", lastname: "Levick"
def full_name(user) do
user.firstname <> " " <> user.lastname
end
end
user = %User{}
User.full_name(user) =>
@rylev
rylev / main.rs
Created September 12, 2018 14:56
Bubble Sort In Rust
fn main() {
let mut sortable: [i32; 5] = [5, 8, 2, 7, 6];
let length = sortable.len();
let mut swapped = true;
print_array(&sortable);
while swapped {
swapped = false;
for i in 1..length {
@rylev
rylev / counter.rs
Created January 26, 2022 17:30
Rust in VS Code Example Code
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = std::env::args()
.skip(1)
.next()
.ok_or("Must supply name of file as first argument")?;
let contents = std::fs::read_to_string(path)?;
let counter = Counter::new(&contents);
@rylev
rylev / declare.rs
Last active July 24, 2020 15:42 — forked from kennykerr/declare.rs
com::declare! {
// A COM interface declared here
#[uuid(...)]
pub interface IOldSchool {
fn foo();
fn bar();
}
// A COM class declared here (not defined here)
#[uuid(...)]
@rylev
rylev / windows-crates.rb
Created July 22, 2019 14:48
Top Windows Crates
require "open-uri"
require "json"
PAGE_SIZE=100
NUM_PAGES=1
crates = (1..NUM_PAGES).flat_map do |page|
res = JSON.parse(URI.parse("https://crates.io/api/v1/crates?keyword=windows&page=#{page}&per_page=#{PAGE_SIZE}").read)
res["crates"].map {|c| {name: c["name"], repo: c["repository"]} }
end
@rylev
rylev / proposal.md
Last active April 13, 2019 16:47
File API Proposal

First we have FileList which is simply a list of Files. This is an opaque struct that offers a way to iterate over Files and get individual files by index:

#[derive(Debug, Clone)]
struct FileList { ... }

impl FileList {
  fn get(index: usize) -> Option<File> { ... }

  fn len(&self) -> usize { ... }