Skip to content

Instantly share code, notes, and snippets.

View andy12530's full-sized avatar

兵兵酱 andy12530

View GitHub Profile
@andy12530
andy12530 / event_emitter.js
Last active August 29, 2015 14:04
跨浏览器,用于iframe之间通信的基础组件
G.add('js/util/event/event_emitter.js', [], function (require, exports, module) {
// Events
// -----------------
// Thanks to:
// - https://github.com/documentcloud/backbone/blob/master/backbone.js
// - https://github.com/joyent/node/blob/master/lib/events.js
// Regular expression used to split event strings
var eventSplitter = /\s+/
@andy12530
andy12530 / gist:4071067
Created November 14, 2012 08:56
JS库中常用的attr方法
/*
如果传来的参数为html集合,则只取第一个节点进行操作
*/
var attr = function(elem, name, value) {
if (!elem)
return ;
if (elem.length > 1) {
elem = elem[0];
}
@andy12530
andy12530 / gist:4064621
Created November 13, 2012 08:15
为不支持的浏览器添加getElementsByClassName与querySelectorAll方法
/*
document.getElementById();
document.getElementsByTagName();
document.getElementsByName();
以上三种方法在主流浏览器中得到原生支持,但是通过class取得元素以及通过css选择器的方式取得元素,即
getElementsByClassName与querySelectorAll未在IE6、7、8中得到完全支持
*/
@andy12530
andy12530 / clientChat.html
Created October 24, 2012 03:16
EventSource Demo【SSE】
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Chat Demo</title>
<style type="text/css">
form {
width: 600px;
margin: 0 auto;
}
@andy12530
andy12530 / socketIo.html
Created October 9, 2012 12:27
Socket.io SSE Demo 跨浏览器、平台
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript">
window.onload = function() {
var socketIo = io.connect('http://localhost');
socketIo.on('connection', function(data) {
@andy12530
andy12530 / chat.html
Created October 8, 2012 13:32
webSocket信息推送
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
window.onload = function() {
var socket = new WebSocket("ws://" + location.host + "/");
socket.onmessage = function(event) {
@andy12530
andy12530 / Connection.php
Created May 27, 2012 03:59
Connect the DB
<?php
class DBCxn{
public static $dsn = 'mysql:host=localhost;dbname=webrss';
public static $user = 'root';
public static $pass = 'root';
//保存连接的内部变量
private static $db;
//不能克隆和技巧化
final private function __construct(){}
final private function __clone(){}