Skip to content

Instantly share code, notes, and snippets.

View fteem's full-sized avatar

Ilija Eftimov fteem

View GitHub Profile
@fteem
fteem / orm.rb
Created December 1, 2011 01:55
My Posts table config
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
@fteem
fteem / ar-dm
Created December 1, 2011 17:19
activerecord vs datamapper
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
@fteem
fteem / sequel_example.rb
Created December 3, 2011 02:18
a gist of sequel
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
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.
mysqldump -u username -p -v olddatabase > olddbdump.sql
mysqladmin -u username -p create newdatabase
mysql -u username -p newdatabase < olddbdump.sql
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”).
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)
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
Randomizer.configure do |config|
config.from = 100
config.to = 200
end
@fteem
fteem / lfu.go
Created February 26, 2019 22:26
Code example for the article "When to use Least Frequenty Used cache and how to implement it in Golang" https://ieftimov.com/golang-least-frequently-used-cache
package main
import (
"container/list"
"fmt"
)
type CacheItem struct {
key string // Key of item
value interface{} // Value of item