Skip to content

Instantly share code, notes, and snippets.

@rainyjune
rainyjune / chrome_developer_tools_watch_expressions.html
Created November 3, 2012 07:30
Chrome Developer Tools 的 Watch Expressions 功能
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chrome Developer Tools</title>
</head>
<body>
<a href="#">click</a>
<script type="text/javascript">
var a = 123;
@rainyjune
rainyjune / gist:4006685
Created November 3, 2012 09:15
JavaScript Try Catch
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chrome Developer Tools</title>
</head>
<body>
<a href="#" id="c">click</a>
<script type="text/javascript">
function t(x){
@rainyjune
rainyjune / gist:4015059
Created November 5, 2012 02:56
JavaScript Object Property Attributes
<!DOCTYPE html>
<html>
<head>
<title>Javascript</title>
</head>
<body>
<script type="text/javascript">
var a={
x:1,
y:2,
@rainyjune
rainyjune / gist:4015316
Created November 5, 2012 04:31
Hosts file
# Trash sites
0.0.0.0 diybl.com
0.0.0.0 jb51.net // Lots of ads
0.0.0.0 tgbus.com
# MSN ADS
127.0.0.1 rad.msn.com
127.0.0.1 rad.live.com
# Activepower ADS
@rainyjune
rainyjune / gist:4015368
Last active October 12, 2015 10:48
DOM selector
//Returns an object reference to the identified element.
function id(i){
return document.getElementById(i);
}
//Returns a list of elements with the given tag name.
function tagName(t){
return document.getElementsByTagName(t);
}
//Returns a list of elements with the given name.
function name(n){
@rainyjune
rainyjune / gist:4084886
Created November 16, 2012 06:48
The best way to retry an AJAX request on failure using jQuery
$.ajax({
url : 'someurl',
type : 'POST',
data : ....,
tryCount : 0,
retryLimit : 3,
success : function(json) {
//do something
},
error : function(xhr, textStatus, errorThrown ) {
@rainyjune
rainyjune / gist:4084898
Created November 16, 2012 06:50
cancel/abort jquery ajax request
$(document).ready(
var xhr;
var fn = function(){
if(xhr && xhr.readyState != 4){
xhr.abort();
}
xhr = $.ajax({
url: 'ajax/progress.ftl',
success: function(data) {
@rainyjune
rainyjune / gist:4088442
Last active October 12, 2015 21:18
.vimrc file
set nocompatible
set tabstop=4
set shiftwidth=4
set softtabstop=4
set smartindent
set hlsearch
set incsearch
set ignorecase
@rainyjune
rainyjune / gist:4388960
Created December 27, 2012 15:05
Querying the scrollbar positions of a window
// Return the current scrollbar offsets as the x and y properties of an object
function getScrollOffsets(w) {
// Use the specified window or the current window if no argument
w = w || window;
// This works for all browsers except IE versions 8 and before
if (w.pageXOffset != null) return {x: w.pageXOffset, y:w.pageYOffset};
// For IE (or any browser) in Standards mode
var d = w.document;
if (document.compatMode == "CSS1Compat") return {x:d.documentElement.scrollLeft, y:d.documentElement.scrollTop};
// For browsers in Quirks mode
@rainyjune
rainyjune / gist:4394233
Created December 28, 2012 03:31
Asynchronously load and execute a script from a specified URL
// Asynchronously load and execute a script from a specified URL
function loadasync(url) {
var head = document.getElementsByTagName("head")[0]; // Find document <head>
var s = document.createElement("script"); // Create a <script> element
s.src = url; // Set its src attribute
head.appendChild(s); // Insert the <script> into head
}