Skip to content

Instantly share code, notes, and snippets.

@lazybios
lazybios / jaccard_recommendation.rb
Last active September 18, 2015 06:13 — forked from otobrglez/jaccard_recommendation.rb
Simple recommendation system written in Ruby based on Jaccard index.
#!/usr/bin/env ruby
# Please read http://otobrglez.opalab.com for more information about this code.
class Book < Struct.new(:title)
def words
@words ||= self.title.gsub(/[a-zA-Z]{3,}/).map(&:downcase).uniq.sort
end
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
gulp.task('sass', function(){
gulp.src('scss/share.scss')
.pipe(sass())
.pipe(gulp.dest('./css'));
});
# Ruby采用模块Mixin。模块是函数和常量的集合,若在类中包含一个模块,那么该模块的行为和常量也会成为类的一部分。
# 定义模块ToFile
module ToFile
# 获取文件名
def filename
"object_name.txt"
end
# 创建文件
class Tree
# 定义实例变量,使用attr或attr_accessor关键字,前者定义变量和访问变量的同名getter方法(即只读),后者定义的变量多了同名setter方法(注意这里使用了符号)
attr_accessor :children, :node_name
# 构造方法(构造方法必须命名为initialize)
def initialize(name, children=[])
@node_name = name
@children = children
end
@lazybios
lazybios / Rakefile
Last active September 5, 2015 15:32 — forked from twistedmind/Rakefile
directory "tmp"
file "tmp/hello.tmp" => "tmp" do
sh "echo 'Hello' > 'tmp/hello.tmp'"
end
task :default => 'morning:turn_off_alarm'
namespace :morning do
desc "Turn off alarm."
#A. Create a Hash
hash = {:key1 => "item1", :key2 => "item2", :key3 => "item3"}
#B. Return a new array of all the Values from the Hash
items = hash.values
#C. Randomly
puts items[rand(items.length)]
module V1
module Entities
class Category < Grape::Entity
expose :title, documentation: {type: 'String', desc: "类别标题"},as: :category
expose :id, documentation: {type: 'Integer', desc: "类别id"}, as: :cid
expose :cover_url, documentation:{type: 'String', desc: "封面图地址"}
expose :years, as: :list_by_year, using: V1::Entities::Year
expose :chapters, as: :list_by_chapter, using: V1::Entities::Chapter
# expose :list_by_year do |instance, options|
# V1::Entities::Year.represent options[:years]
@lazybios
lazybios / cancan-grape.rb
Last active August 26, 2015 15:04 — forked from thomasbiddle/cancan-grape.rb
CanCan helper for a Grape API implementation
def authorize!(role={}, object)
ability = Ability.new(current_user)
unless ability.can?(role, object)
unauthorized!
end
end
sqlite3 test.sqlite3
sqlite> create table awesome_video_games(name text, type text);
sqlite> insert into awesome_video_games values('fallout', 'rpg');
sqlite> insert into awesome_video_games values('final fantasy', 'rpg');
sqlite> insert into awesome_video_games values('deus ex', 'rpg');
sqlite> insert into awesome_video_games values('hitman', 'stealth');
sqlite> select * from awesome_video_games where type='rpg';
fallout|rpg
final fantasy|rpg

我从三个方面谈谈我的考研经历,希望可以给大家一点启示!

心理篇 我将心理因素放在首位以突出其重要性。在我看来,考研不仅仅考察了学习能力,也是对心理调节能力的进一步磨练。

一、考研前的心理准备 1)明确考研目的。我们一定要清楚自己考研的原因,无论目的是什么,存在即合理。我考研是因为我想转换方向,大学里曾尝试拍摄过一些视频、纪录片等,有媒体实习的经验,自己对广播电视这个行业的兴趣也日趋浓厚,渴望进一步的学习。很多同学因为没有明确自己的目标,遇到困难没有信念支撑,到后期都陆续放弃了。 2)信心、恒心、耐心。毋庸赘言,明确了目标,一定要具备这些心理因素才能在这场长跑中坚持下来。考研的学习强度不比高考小,遇到的困难也异常多,这些因素不能保证你最后的成功,但能助你坚持到最后。