Skip to content

Instantly share code, notes, and snippets.

Ilija Eftimov fteem

Block or report user

Report or block fteem

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@fteem
fteem / lfu.go
Created Feb 26, 2019
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
View lfu.go
package main
import (
"container/list"
"fmt"
)
type CacheItem struct {
key string // Key of item
value interface{} // Value of item
View gist:1d4651950fdfa4db52e5
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
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
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
mysqldump -u username -p -v olddatabase > olddbdump.sql
mysqladmin -u username -p create newdatabase
mysql -u username -p newdatabase < olddbdump.sql
View gist:1470124
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
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
@fteem
fteem / ar-dm
Created Dec 1, 2011
activerecord vs datamapper
View ar-dm
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 / orm.rb
Created Dec 1, 2011
My Posts table config
View orm.rb
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
You can’t perform that action at this time.