This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
size_t S(size_t n, size_t k) | |
{ | |
if(k > n) | |
{ | |
return 0; | |
} | |
else if(k == 1) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.alexonlinux.com/multithreaded-simple-data-type-access-and-atomic-variables | |
// gcc -lpthread -D_GNU_SOURCE -o atomic atomic.c | |
#include <stdio.h> | |
#include <pthread.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <sched.h> | |
#include <linux/unistd.h> | |
#include <sys/syscall.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
class Tree | |
attr_accessor :children, :node_name | |
def initialize(name, children) | |
@children = children | |
@node_name = name | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
module ToFile | |
def filename | |
"object_#{self.object_id}.txt" | |
end | |
def to_f | |
File.open(filename, 'w') {|f| f.write(to_s)} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Roman | |
def self.method_missing name, *args | |
roman = name.to_s | |
roman.gsub!("IV" , "IIII" ) | |
roman.gsub!("IX" , "VIIII" ) | |
roman.gsub!("XL" , "XXXX" ) | |
roman.gsub!("XC" , "LXXXX" ) | |
(roman.count("I" ) + | |
roman.count("V" ) * 5 + | |
roman.count("X" ) * 10 + |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST_F(SExpTest, SExpWithOperator) | |
{ | |
// (2 3) | |
SExp* valuePair = new SExp(a, b); | |
// (+, (2 3)) = 5 | |
SExp* addOpWithValue = new SExp(new AddOperator(), valuePair); | |
EXPECT_EQ(5, addOpWithValue->Evaluate(context)); | |
delete addOpWithValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# constants | |
COMPILER = "g++" | |
EXEC = "hello" | |
FLAGS = "-Wall -Wextra" | |
OBJECTS = ['hello.o', 'add.o'] | |
file 'hello' => OBJECTS | |
# tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rake/clean' | |
PROG = "foo" | |
LIBNAME = PROG | |
LIBFILE = "lib#{LIBNAME}.a" | |
SRC = FileList['**/*.cpp'] | |
OBJDIR = 'obj' | |
OBJ = SRC.collect { |fn| File.join(OBJDIR, File.basename(fn).ext('o')) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shoes.app :height => 150, :width => 250 do | |
background rgb(240, 250, 208) | |
stack :margin => 10 do | |
button "Start" do | |
@time = Time.now | |
@label.replace "Stop watch started at #@time" | |
end | |
button "Stop" do | |
@label.replace "Stopped, ", strong("#{Time.now - @time}"), " seconds elapsed." | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class Bird | |
{ | |
public: | |
virtual void Fly() const = 0; | |
virtual void Speak() const = 0; | |
}; | |
class Eagle : public Bird |
OlderNewer