Skip to content

Instantly share code, notes, and snippets.

View jay16's full-sized avatar

俊杰.li jay16

View GitHub Profile
@jay16
jay16 / js获取对象所有方法与属性
Created December 16, 2013 08:00
js获取对象所有方法与属性
<script src="http://solife.us/assets/jquery.js" type="text/javascript"></script>
<script>
$(function(){
$("svg path").on("click", function(e){
var obj = e.target;
var PropertyList='';
for(i in obj){
if(obj.i !=null)
PropertyList=PropertyList+i+'属性:'+obj.i+'\r\n';
else
#!/usr/bin/env ruby
timestamp = Time.now.strftime("%Y/%m/%d-%H:%M:%S")
shell_content =<<SHELL
git_path=$(which git)
cd /home/work/solife
${git_path} init
${git_path} add -A .
${git_path} commit -a -m "auto commit - #{timestamp}"
#encoding: utf-8
require "fileutils"
require 'qiniu-rs'
#===============================================
#数据库备份位置
db_bak_path = "/home/work/solife/db/db.bak"
raise "db_bak_path:#{db_bak_path}" unless File.exist?(db_bak_path)
系统环境:centos 5.5
需要文件:
sqlite-amalgamation-3.6.16.tar.gz (sqlite安装包)
ruby-1.9.2-p180.tar.gz (ruby1.9.2安装包)
node-v0.4.8.tar.gz (nodejs安装包)
redis-2.4.16.tar.gz (redis安装包)
focus_mail.tar.gz (FocusMail源代码,解压后文件夹名为focus_mail_128,应修改为focus_mail)
mail206.tar.gz (FocusMail数据库内容)
redis.conf (redis配置文件,放置/etc下)
## 现场再现
在view中form属性设置`remote: true`即通过ajax提交时,controller会创建两次,查看log文件发现也确实提交了两次。
之前,还出现过在界面未刷新情况下,每通过ajax提交一次,controller中创建次数会增加一次,比如第一次创建提交会实质提交两次,第二次创建提交会提交三次...
这样的问题让人很无奈,因为在其他view中的创建提交都很正常,郁闷了好久,直到前段时间才发现原因,理解了为什么,心中不觉释然。
## 原因 & 解决方案
@jay16
jay16 / javascript加减日期
Created December 8, 2013 11:09
按天为单位对input日期进行加减
<script>
function add_plus_date(fname,yn){
var source = document.getElementById(fname);
var reg=/^ *(\d{4})-(\d{1,2})-(\d{1,2}) +(\d{1,2}):(\d{1,2}):(\d{1,2}) *$/;
if(ret = source.value.match(reg)){
var old_date = new Date(ret[1],parseInt(ret[2])-1,ret[3],ret[4],ret[5],ret[6],0);
var tmp_date = old_date.valueOf() + (yn=='add' ? +1 : -1 ) * 24*60*60*1000;
var tmp_date = new Date(tmp_date);
var y = tmp_date.getFullYear();
var m = tmp_date.getMonth() + 1;
## Rack介绍
Rack为使用Ruby开发web应用提供了一个最小的模块化和可修改的接口。用可能最简单的方式来包装HTTP请求和响应,它为web 服务器,web框架和中间件的API进行了统一并提纯到了单一的方法调用。
一个`Rack app`的Ruby对象被调用,参数env包括一个环境变量和请求参数的散列,代码块的返回值由带有三个元素的数组组成: HTTP状态码、响应头和响应体
### HTTP
> 超文本转移协议 (HTTP-Hypertext transfer protocol) 是一种详细规定了浏览器和万维网服务器之间互相通信的规则,通过因特网传送万维网文档的数据传送协议。
@jay16
jay16 / 书籍
Last active December 29, 2015 21:19
## Rack
A Quick Introduction to Rack
http://rubylearning.com/blog/a-quick-introduction-to-rack/
Ruby on Rack #1 - Hello Rack!
http://m.onkey.org/ruby-on-rack-1-hello-rack
Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.
The exact details of this are described in the Rack specification, which all Rack applications should conform to.
## Supported web servers
The included handlers connect all kinds of web servers to Rack:
1. Mongrel
2. EventedMongrel
@jay16
jay16 / gem error: mongrel 安装失败
Last active December 29, 2015 21:09
gem error: mongrel 安装失败
## 概念
### Rack
1. A Rack application is an Ruby object (not a class) that responds to **call**. It takes exactly one argument, the environment and returns an Array of exactly three values: **The status**, **the headers**, and **the body**.
2. Rack is a framework to roll your own ruby framework.
3. Rack provides an interface between different web servers and your framework/application. Making it very simple for your framework/application to be compatible with any webserver that supports Rack – Phusion Passenger, Litespeed, Mongrel, Thin, Ebb, Webrick to name a few.
4. Rack cuts your chase. You get request, response, cookies, params & sessions for free.
5. Makes it possible to use multiple frameworks for the same application, provided there is no class collision. Rails and sinatra integration is a good example of this.