Skip to content

Instantly share code, notes, and snippets.

View zhuliangyu's full-sized avatar

Ricky Zhu zhuliangyu

View GitHub Profile
@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)
@zhuliangyu
zhuliangyu / out.c
Last active September 21, 2020 04:18
313 C
//outout Hex 0x30 0xf2 0x08....
printf(" %02x", p[i]);
printf("\n");
//表示byte 指针时,都用unsigned char
@zhuliangyu
zhuliangyu / console
Last active September 25, 2020 22:29
rspec
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
@zhuliangyu
zhuliangyu / comments_controller.rb
Created November 12, 2016 22:06
use cancancan
def destroy
# render plain:"asd"
comment_id=params[:id]
@comment=Comment.find(comment_id)
@idea=@comment.idea
if can? :delete, @comment
@zhuliangyu
zhuliangyu / ability.rb
Created November 12, 2016 22:03
a example to write ability file for cancancan
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :like, Idea do |idea|
idea.user!=user
end
@zhuliangyu
zhuliangyu / app.js
Last active November 12, 2016 20:35
var express=require('express');
var app=express();
app.get('/',function (req, res) {
res.send('asddas');
});
@zhuliangyu
zhuliangyu / application_controller.rb
Created October 26, 2016 02:15
authenticate authorize controller
#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
@zhuliangyu
zhuliangyu / gist:8decf91901df2d132e02b9d42d7fe6c0
Created September 13, 2016 20:29
【Ruby】模块扩展方法介绍
当我们要扩展类的方法时,我们可以采取Mixin的方式将模块中的方法添加到类中,下面会对实现的几种方式进行详细介绍:
1. include和extend
使用include,可以将模块中定义的方法作为实例方法添加到类中;使用extend,可以将模块中定义的方法作为类方法添加到类中。
下面的例子是include的使用方法。
[ruby] view plain copy
module MyMod
def method
end
@zhuliangyu
zhuliangyu / data_mapper.rb
Created September 10, 2016 20:30
data_mapper
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.
@zhuliangyu
zhuliangyu / sinatra_controller.rb
Last active September 12, 2016 18:12
sinatra
require "sinatra"
require "sinatra/reloader"
get "/" do
erb :index
erb (:index,{layout: :default_layout})
end
# get params from url