Skip to content

Instantly share code, notes, and snippets.

View nightire's full-sized avatar
Looking for new opportunities

余凡 nightire

Looking for new opportunities
View GitHub Profile
@nightire
nightire / 解决 Git 在 windows 下中文乱码的问题.md
Last active April 24, 2024 16:19
解决 Git 在 windows 下中文乱码的问题

解决 Git 在 windows 下中文乱码的问题

原因

中文乱码的根源在于 windows 基于一些历史原因无法全面支持 utf-8 编码格式,并且也无法通过有效手段令其全面支持。

解决方案

  1. 安装
@nightire
nightire / Git on the Server.md
Last active August 8, 2016 15:53
Git on the Server

Git on the Server

远程代码库通常只是一个“纯仓库”(bare repository)——一个没有当前工作目录的仓库;仓库里仅仅是 Git 的数据,也就是 .git 目录里的内容。

协议

Git 可使用四种协议来传输数据:

  1. 本地传输
  2. SSH 协议
@nightire
nightire / Rails 4 - Active Record Query Interface.md
Created March 9, 2013 15:00
Rails 4 - Active Record Query Interface

Rails 4 - Active Record Query Interface

批量查询记录

我们时常会碰到需要一次性处理大量记录的要求,比如说为所有的用户发送电子邮件:

User.all.each do |user|
  NewsLetter.weekly_deliver(user)
end
@nightire
nightire / Rails 4 - Active Record Associations.md
Last active March 27, 2016 12:40
Rails 4 - Active Record Associations

Rails 4 - Active Record Associations

has_one

一对一关系:有 A 和 B,A 拥有且仅拥有一个 B

has_one

belongs_to

@nightire
nightire / define_method.md
Last active March 29, 2018 09:01
善用 define_method

善用 define_method

define_method 可以帮助我们动态的,快速的定义多个方法;比如有这样一个类:

class Post
  attr_accessor :title, :content, :state

  def initialize(title, content, state = :draft)
    @title, @content, @state = title, content, state
@nightire
nightire / How to use Backbone.js.md
Last active November 14, 2017 08:15
How to use Backbone.js

Simple Starting Point

创建 Model

var Person = Backbone.Model.extend();
@nightire
nightire / Changes in Rails 4_1.md
Last active May 11, 2022 04:50
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@nightire
nightire / year_to_chinese_era.md
Created June 25, 2013 12:01
公历年份转换为中国纪元(天干地支)的方法

公历年份转换为中国纪元(天干地支)的方法

1. 为天干编码

0 1 2 3 4 5 6 7 8 9

凡是公元后年份,减4后除10取余,即得该年天干名称。

Web 中文字体应用指南

在 Web 上应用字体是一项基本技术,同时也是一门艺术。对于英文字体来说可选择的范围实在是太广泛了,合理的使用它们将会为你的网站增色不少。关于英文字体的使用和搭配技巧,在这里不做赘述,只推荐一套非常好的视频:Fundamentals of Design by CodeSchool

而真正的挑战在于中文字体,由于中文字体组成的特殊性导致其体积过于庞大,除了操作系统内置的字体之外,我们很难在网站上应用其他的字体。在可选性很差的前提之下,如何正确的使用中文字体呢?

首先,以下的字体声明都是很糟糕的,切忌使用:

font-family: "宋体";
@nightire
nightire / .vimrc
Last active May 25, 2022 03:14
Vim 基础配置
set nocompatible " use vim defaults
set t_RV= " http://bugs.debian.org/608242
" set runtimepath=$VIMRUNTIME " turn off user scripts, https://github.com/igrigorik/vimgolf/issues/129
syntax on " turn syntax highlighting on by default
filetype on " detect type of file
filetype indent on " load indent file for specific file type
set nobackup " do not keep a backup file
set novisualbell " turn off visual bell