Skip to content

Instantly share code, notes, and snippets.

View steveklabnik's full-sized avatar
🦀
Rustacean

Steve Klabnik steveklabnik

🦀
Rustacean
View GitHub Profile
extern mod std;
fn is_three(num: int) -> bool {
num % 3 == 0
}
#[test]
fn test_is_three_with_not_three() {
if is_three(1) {
fail ~"One is not three";
trait Monster {
fn attack(&self);
static fn new() -> self;
}
struct IndustrialRaverMonkey {
life: int,
strength: int,
charisma: int,
weapon: int,
require 'nokogiri'
require 'open-uri'
class CardGenerator
def initialize(format)
@format = format
end
def random_card
html = ""
$ ack -ri "Test::Unit" *
actionpack/lib/action_controller/test_case.rb
308: # Test::Unit::TestCase and define @controller, @request, @response in +setup+.)
activesupport/lib/active_support/inflector/methods.rb
205: # 'Test::Unit'.constantize # => Test::Unit
249: # 'Test::Unit'.safe_constantize # => Test::Unit
activesupport/lib/active_support/test_case.rb
20: class TestCase < ::MiniTest::Unit::TestCase
@steveklabnik
steveklabnik / number_game.rs
Created January 2, 2013 22:08
A guessing game in Rust.
use io::{Reader,ReaderUtil};
use core::rand::{Rng};
use core::int::abs;
fn generate_secret_number() -> int {
abs(Rng().gen_int() % 100) + 1
}
fn process_guess(secret:int, guess: int, guesses: &mut int) {
io::println(fmt!("You guessed: %d", guess));
$ vulcan build -s ~/src/rust -p /tmp/rust -c "./configure --prefix=/tmp/rust && make && make install" --verbose
Packaging local directory... done
Uploading source package... done
Building with: ./configure --prefix=/tmp/rust && make && make install
configure: looking for configure programs
configure: found cmp
configure: found mkdir
configure: found printf
configure: found cut
configure: found head
irb(main):008:0> p = :nil?.to_proc
=> #<Proc:0x007ff4a5078158>
irb(main):009:0> [1,nil].reject(p)
ArgumentError: wrong number of arguments(1 for 0)
from (irb):9:in `reject'
from (irb):9
from /usr/local/ruby-1.9.3-p327/bin/irb:12:in `<main>'
irb(main):010:0> [1,nil].reject(&p)
=> [1]
set nocompatible " We're running Vim, not Vi!
set guifont=Bitstream\ Vera\ Sans\ Mono:h24
let g:molokai_original = 1
colorscheme molokai
syntax on " Enable syntax highlighting
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
@steveklabnik
steveklabnik / evil.rb
Last active December 13, 2015 19:48
Don't even think about this.
$pointsz = Hash.new(0)
class Class
method_blacklist = [:method_added, :===, :to_s, :send, :public_methods, :new]
methods_to_redefine = public_methods.reject{|m| method_blacklist.include? m }
methods_to_redefine.each do |m|
new_name = "__lol_omg_#{m}"
define_method m do |*args, &blk|
@steveklabnik
steveklabnik / gist:4981528
Created February 18, 2013 22:56
gschool blog feed link converter
text = `curl https://raw.github.com/gSchool/submissions/master/writing/index.markdown`
text.split("\n").each do |line|
next unless line =~ /\*/
line =~ /\* (?:\w|\s)+: (.*)/
puts $1 + "/feed.xml"
end