Skip to content

Instantly share code, notes, and snippets.

View steveklabnik's full-sized avatar
🦀
Rustacean

Steve Klabnik steveklabnik

🦀
Rustacean
View GitHub Profile
@steveklabnik
steveklabnik / quality.rake
Created July 11, 2011 20:18
My new favorite Rake task
require 'flog'
require 'flog_task'
require 'flay'
require 'flay_task'
require 'roodi'
require 'roodi_task'
FlogTask.new :flog, SOME_NUMBER_HERE, %w[app lib]
FlayTask.new :flay, OTHER_NUMBER_HERE, %w[app lib]
RoodiTask.new 'roodi', ['app/**/*.rb', 'lib/**/*.rb']
@steveklabnik
steveklabnik / summary.md
Created September 29, 2015 14:39
my summary of "using Rust with Ruby: a deep dive with Yehuda Katz"

My summary of https://www.youtube.com/watch?v=IqrwPVtSHZI

TL;DR:

Rails has a library, ActiveSupport, which adds methods to Ruby core classes. One of those methods is String#blank?, which returns a boolean (sometimes I miss this convention in Rust, the ?) if the whole string is whitespace or not. It looks like this: https://github.com/rails/rails/blob/b3eac823006eb6a346f88793aabef28a6d4f928c/activesupport/lib/active_support/core_ext/object/blank.rb#L99-L117

It's pretty slow. So Discourse (which you may know from {users,internals}.rust-lang.org) uses the fast_blank gem, which provides this method via a C implementation instead. It looks like this: https://github.com/SamSaffron/fast_blank/blob/master/ext/fast_blank/fast_blank.c

For fun, Yehuda tried to re-write fast_blank in Rust. Which looks like this:

@steveklabnik
steveklabnik / main.rs
Last active January 16, 2018 13:32 — forked from jefftime/main.rs
#![feature(lang_items, start)]
#![no_std]
#[link(name = "c")]
extern {
fn puts(s: *const u8) -> isize;
fn abort() -> !;
}
#[lang = "panic_fmt"]
use std::rc::Rc;
fn main() {
let x = Rc::new(5i);
for _ in range(0, 10u) {
println!("{}", x)
}
}
@steveklabnik
steveklabnik / boot.asm
Created July 6, 2017 16:16 — forked from faraazahmad/boot.asm
error on make
global start
section .text
bits 32
start:
; Point the first entry of the level 4 page table to the first entry in the
; p3 table
mov eax, p3_table
or eax, 0b11 ;
mov dword [p4_table + 0], eax
@steveklabnik
steveklabnik / passes.txt
Created May 9, 2017 22:06
-Z time-passes for sparkles
Compiling sparkles v0.1.0 (file:///C:/Users/steve/src/sparkles)
time: 0.003; rss: 17MB parsing
time: 0.000; rss: 17MB recursion limit
time: 0.000; rss: 17MB crate injection
time: 0.000; rss: 17MB plugin loading
time: 0.000; rss: 17MB plugin registration
time: 0.241; rss: 89MB expansion
time: 0.000; rss: 89MB maybe building test harness
time: 0.000; rss: 89MB maybe creating a macro crate
time: 0.000; rss: 89MB checking for inline asm in case the target doesn't support it
pub fn sum_loop(nums: &[i32]) -> i32 {
let mut s = 0;
for i in nums {
s = s + i;
}
s
}
fn add_to_mutable_reference(x: &mut i32) {
*x +=1;
}
#[test]
fn mutable_reference_test() {
let mut x = 5;
let y = &mut x;
mutable_reference(y);

9:05- 9:25 1. Welcome and Introduction (20min)

  • Operational Stuff (10min) [Ashley]

    • Introduction to instructors
    • Where are all the materials
    • Explain the schedule, when are breaks
    • Code of Conduct
    • What to do if you need help
  • What is the intermezzOS project? (10min) [Steve]

extern crate rand;
extern crate byteorder;
use std::io::{ Write };
use byteorder::{LittleEndian, WriteBytesExt};
const SAMPLE_RATE: u32 = 44100;
const CHANNELS: u32 = 1;
const HEADER_SIZE: u32 = 36;
const SUBCHUNK1_SIZE: u32 = 16;