This file contains hidden or 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
| @Id | |
| @GeneratedValue(strategy = GenerationType.IDENTITY) | |
| @Column(name = "id", nullable = false) | |
| private Long id; | |
| @Enumerated(EnumType.STRING) | |
| @Column(name = "deliveryChannel", nullable = false) | |
| private EDeliveryChannel deliveryChannel; | |
| @Temporal(TemporalType.TIMESTAMP) |
This file contains hidden or 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
| //outout Hex 0x30 0xf2 0x08.... | |
| printf(" %02x", p[i]); | |
| printf("\n"); | |
| //表示byte 指针时,都用unsigned char |
This file contains hidden or 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
| rails g rspec:install | |
| create a rspect for controller | |
| rails g rspec:controller passwords | |
| create a rspect for model | |
| rails g rspec:model widget | |
| rails g factory_girl:model Car name speed:integer |
This file contains hidden or 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
| def destroy | |
| # render plain:"asd" | |
| comment_id=params[:id] | |
| @comment=Comment.find(comment_id) | |
| @idea=@comment.idea | |
| if can? :delete, @comment |
This file contains hidden or 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 Ability | |
| include CanCan::Ability | |
| def initialize(user) | |
| user ||= User.new | |
| can :like, Idea do |idea| | |
| idea.user!=user | |
| end |
This file contains hidden or 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
| var express=require('express'); | |
| var app=express(); | |
| app.get('/',function (req, res) { | |
| res.send('asddas'); | |
| }); |
This file contains hidden or 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
| #application controller | |
| def authenticate_user | |
| redirect_to new_session_path, alert: 'please sign in' unless user_signed_in? | |
| end | |
| def user_signed_in? | |
| session[:user_id].present? | |
| end | |
| helper_method :user_signed_in? # adding this line makes this mehtod accessible |
This file contains hidden or 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
| 当我们要扩展类的方法时,我们可以采取Mixin的方式将模块中的方法添加到类中,下面会对实现的几种方式进行详细介绍: | |
| 1. include和extend | |
| 使用include,可以将模块中定义的方法作为实例方法添加到类中;使用extend,可以将模块中定义的方法作为类方法添加到类中。 | |
| 下面的例子是include的使用方法。 | |
| [ruby] view plain copy | |
| module MyMod | |
| def method | |
| end |
This file contains hidden or 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 "data_mapper" | |
| DataMapper.setup(:default, "sqlite://#{Dir.pwd}/app.db") | |
| # class name must be singular. DataMapper will user a pluralized name for the | |
| # table. For instance, in this case it will be `contacts` | |
| class Contact | |
| # this integrates our class with DataMapper so it will do things like creating | |
| # or updating the table and columns inside the table. It will also give us | |
| # extra methods to interact with table rows. |
This file contains hidden or 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 "sinatra" | |
| require "sinatra/reloader" | |
| get "/" do | |
| erb :index | |
| erb (:index,{layout: :default_layout}) | |
| end | |
| # get params from url |
NewerOlder