Skip to content

Instantly share code, notes, and snippets.

View annoyingecho.rs
use std::io;
use std::io::Write;
fn main() {
//println! is a macro that writes a line to stdout and then flushes the
//stdout buffer
println!("The inredibly annoying Rust echo strikes again!");
//get a reference to stdin
let stdin = io::stdin();
@willmurphyscode
willmurphyscode / scientific_names_regex.rs
Created Nov 15, 2016
A regex to tell you whether a string is a "scientific name". (Note: very scientific)
View scientific_names_regex.rs
extern crate regex;
use regex::Regex;
/*
1. At least 1 "cool" adjective ("horrendous", "incredible", "monstrous", "ultimate")
2. A science-sounding intermediate noun ("space", "time", "matter", "energy")
3. An onomatopoeia that makes a cool sound ("boom", "kablooie", "swoosh")
*/
pub fn is_scientific_name(input: &str) -> bool {
View scientific_names_lalrpop_sample.rs
//from scientific_names.lalrpop
// parse the final noun of a scientific name.
// match it to one of the legal final nouns.
pub FinalNoun : FinalNoun = {
"kablooie" => FinalNoun::Kablooie,
"swoosh" => FinalNoun::Swoosh,
"frobber" => FinalNoun::Frobber,
"atomizer" => FinalNoun::Atomizer,
"event" => FinalNoun::Event,
"device" => FinalNoun::Device,
View rectangles_bad.rs
//src/main.rs
mod rectangle;
fn main() {
println!("Hello, world!");
}
//src/point.rs
#[derive(Debug)]
pub struct Point {
View rectangles_good.rs
//src/main.rs
mod rectangle;
mod point;
fn main() {
println!("Hello, world!");
}
//src/point.rs
#[derive(Debug)]
View simple rails vagrant file.rb
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
@willmurphyscode
willmurphyscode / instance_and_class.rb
Created Mar 6, 2017
Error calling class methods from instance methods in Ruby
View instance_and_class.rb
class HasInstanceMethods
def instance_method
puts "In instance method, the type of `self` is #{self.class}"
end
def self.class_method
puts "In class method, the type of `self` is #{self.class}"
end
def call_class_from_instance
View HasInstanceAndStaticMethods.cs
using System;
namespace ConsoleApplication
{
public class HasInstanceAndStaticMethods
{
public static void StaticMethod()
{
Console.WriteLine("Hello from static method");
}
@willmurphyscode
willmurphyscode / csharp_style.rb
Created Mar 6, 2017
An object that intercepts `method_messing` so that it appears you can call class
View csharp_style.rb
class CSharpStyle
def method_missing method_name, *args
self.class.send(method_name, *args)
end
def self.static_method
puts "hurray for Ruby"
end
def instance_method
View stubbable.rb
class Stubbable
def stub(name, block)
send(:define_singleton_method, name, block)
end
end
class Class
def stub(name, block)
send(:define_singleton_method, name, block)
end