Skip to content

Instantly share code, notes, and snippets.

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 November 15, 2016 12:31
A regex to tell you whether a string is a "scientific name". (Note: very scientific)
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 {
//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,
//src/main.rs
mod rectangle;
fn main() {
println!("Hello, world!");
}
//src/point.rs
#[derive(Debug)]
pub struct Point {
//src/main.rs
mod rectangle;
mod point;
fn main() {
println!("Hello, world!");
}
//src/point.rs
#[derive(Debug)]
# -*- 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 March 6, 2017 11:57
Error calling class methods from instance methods in Ruby
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
using System;
namespace ConsoleApplication
{
public class HasInstanceAndStaticMethods
{
public static void StaticMethod()
{
Console.WriteLine("Hello from static method");
}
@willmurphyscode
willmurphyscode / csharp_style.rb
Created March 6, 2017 12:06
An object that intercepts `method_messing` so that it appears you can call class
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
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