Skip to content

Instantly share code, notes, and snippets.

View caok's full-sized avatar

Clark caok

View GitHub Profile
window.onload
必须等待网页中所有的内容加载完毕后(包括图片)才能执行
不能同时编写多个,比如:
window.onload = function() {
alert("111");
};
window.onload = function() {
alert("222");
@caok
caok / gist:8487368
Created January 18, 2014 07:21
键盘上下键头选中div的内容
<html>
<head>
<title>SimulateUpDownKeySelect</title>
</head>
<body>
<input type="text" id="txtInput"/>
<div id="divSelect">
<li>123</li>
<li>456</li>
@caok
caok / gist:8643896
Created January 27, 2014 06:08
如何让元素位于DIV内的底部
<div id="a">
<ul>
<li class="b">位于底部</li>
</ul>
</div>
<style>
#a{
width:200px;
height:200px;
@caok
caok / gist:8877936
Created February 8, 2014 07:22
如何在Node.js中获取本机IP地址
//获取本地IP地址
var os = require('os');
var IPv4,hostName;
hostName=os.hostname();
for(var i=0;i<os.networkInterfaces().eth0.length;i++){
if(os.networkInterfaces().eth0[i].family=='IPv4'){
IPv4=os.networkInterfaces().eth0[i].address;
}
}
console.log('----------local IP: '+IPv4);
@caok
caok / gist:9086913
Created February 19, 2014 06:14
jquery 事件冒泡
冒泡事件就是点击子节点,会向上触发父节点,祖先节点的点击事件。
下面是html代码部分:
<body>
<div id="content">
外层div元素
<span>内层span元素</span>
外层div元素
</div>
@caok
caok / gist:9105599
Created February 20, 2014 01:58
HTML页面内容禁止选择、复制、右键
<body leftmargin=0 topmargin=0 oncontextmenu='return false' ondragstart='return false' onselectstart ='return false' onselect='document.selection.empty()' oncopy='document.selection.empty()' onbeforecopy='return false' onmouseup='document.selection.empty()'>
关键就在
oncontextmenu='return false'
ondragstart='return false'
onselectstart ='return false'
onselect='document.selection.empty()'
oncopy='document.selection.empty()'
onbeforecopy='return false'
onmouseup='document.selection.empty()'
@caok
caok / gist:9c78656dab290da40902
Last active August 29, 2015 14:03
应用环境构筑

更新源

sudo apt-get update

安装系统包

sudo apt-get -y install git-core curl exuberant-ctags vim autoconf automake openssl \
  build-essential libc6-dev libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev \
  mysql-server libmysqlclient-dev libsqlite3-0 libsqlite3-dev sqlite3 \
@caok
caok / PostgreSQL.md
Last active October 31, 2020 01:10
PostgreSQL

安装

sudo apt-get install postgresql
sudo apt-get install libpq-dev
# for hstore
sudo apt-get install postgresql-contrib

安装9.5

@caok
caok / devise.md
Last active August 29, 2015 14:08
  • rails generate devise:install

  • rails rails generate devise MODEL

  • rake db:migrate

  • rails generate devise:views

  • rails generate devise:controllers [scope]

you need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for config/environments/development.rb:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
@caok
caok / gist:f8df7e1a9aa5b402cc21
Created November 1, 2014 08:56
加密、解密字段
before_save :encrypt_note
def encrypt_note
salt = SecureRandom.random_bytes(64)
key = encrypt_key || ActiveSupport::KeyGenerator.new(ENV["SECRET_KEY"]).generate_key(salt)
crypt = ActiveSupport::MessageEncryptor.new(key)
%w(client_note food medicines hydration md_appointments activity mood positive_thinking positive_action listener_note).each_with_index do |att|
val = if !new_record? and send("#{att}_changed?")
read_attribute(att.to_sym)