View lfu.go
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
package main | |
import ( | |
"container/list" | |
"fmt" | |
) | |
type CacheItem struct { | |
key string // Key of item | |
value interface{} // Value of item |
View randomizer.config.rb
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
Randomizer.configure do |config| | |
config.from = 100 | |
config.to = 200 | |
end |
View gist:1d4651950fdfa4db52e5
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 Student | |
attr_accessor :first_term_home_work, :first_term_test, :first_term_paper attr_accessor, | |
:second_term_home_work, :second_term_test, :second_term_paper | |
def first_term_grade | |
(first_term_home_work + first_term_test + first_term_paper) / 3 | |
end | |
def second_term_grade | |
(second_term_home_work + second_term_test + second_term_paper) / 3 |
View gist:5568642
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
describe ".send_surveys" do | |
it "sends those users an email with survey" do | |
SurveySender.should_receive(:unsurveyed_users).and_return [user, user2] | |
SurveyMailer.should_receive(:send_survey).with(user).and_return mailer = double(:mailer) | |
mailer.should_receive(:deliver) | |
user.should_receive(:email) | |
Rails.logger.should_receive(:info) |
View gist:1470134
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
12.1.32. RENAME DATABASE Syntax | |
RENAME {DATABASE | SCHEMA} db_name TO new_db_name; | |
This statement was added in MySQL 5.1.7 but was found to be dangerous and was removed in MySQL 5.1.23. It was intended to enable upgrading pre-5.1 databases to use the encoding implemented in 5.1 for mapping database names to database directory names (see Section 8.2.3, “Mapping of Identifiers to File Names”). However, use of this statement could result in loss of database contents, which is why it was removed. Do not use RENAME DATABASE in earlier versions in which it is present. | |
To perform the task of upgrading database names with the new encoding, use ALTER DATABASE db_name UPGRADE DATA DIRECTORY NAME instead (see Section 12.1.1, “ALTER DATABASE Syntax”). |
View gist:1470128
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
mysqldump -u username -p -v olddatabase > olddbdump.sql | |
mysqladmin -u username -p create newdatabase | |
mysql -u username -p newdatabase < olddbdump.sql |
View gist:1470124
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
12.1.32. RENAME DATABASE Syntax | |
RENAME {DATABASE | SCHEMA} db_name TO new_db_name; | |
This statement was added in MySQL 5.1.7 but was found to be dangerous and was removed in MySQL 5.1.23. It was intended to enable upgrading pre-5.1 databases to use the encoding implemented in 5.1 for mapping database names to database directory names (see Section 8.2.3, “Mapping of Identifiers to File Names”). However, use of this statement could result in loss of database contents, which is why it was removed. Do not use RENAME DATABASE in earlier versions in which it is present. |
View sequel_example.rb
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 "rubygems" | |
require "sequel" | |
# connect to an in-memory database | |
DB = Sequel.sqlite | |
# create an items table | |
DB.create_table :items do | |
primary_key :id | |
String :name |
View ar-dm
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
ActiveRecord Terminology DataMapper Terminology | |
has_many has n | |
has_one has 1 | |
belongs_to belongs_to | |
has_and_belongs_to_many has n, :things, :through => Resource | |
has_many :association, :through => Model has n, :things, :through => :model |
View orm.rb
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
DataMapper::setup(:default, "sqlite3://#{Dir.pwd}/blog.db") | |
class Post | |
include DataMapper::Resource | |
property :id, Serial | |
property :title, String | |
property :body, Text | |
property :created_at, DateTime | |
property :updated_at, DateTime | |
end |