Skip to content

Instantly share code, notes, and snippets.

View gindis's full-sized avatar
✍️
I may be slow to respond.

gindis gindis

✍️
I may be slow to respond.
  • Taobao
  • hangzhou
View GitHub Profile
function getByteLen(val) {
var len = 0;
for (var i = 0; i < val.length; i++) {
var a = val.charAt(i);
if (a.match(/[^\x00-\xff]/ig) != null) {
len += 2;
} else {
len += 1;
}
}
@gindis
gindis / grids.html
Last active October 10, 2015 09:14
栅格
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Grids</title>
<style>
html,
body {
margin: 0;
padding: 0;
@gindis
gindis / sort.js
Created October 7, 2015 03:48 — forked from sofish/sort.js
safari 不能用 true / false 来做排序
// firefox 和 chrome 是 [1024, 6, 5, 3, 2, 1]
// safari 中顺序没变
[1,3,2,5,6,1024].sort(function(a, b) {
return b > a;
});
// 在各中浏览器工作一致的方法
// 用正负和零来排序,而不是 true/false
[1,3,2,5,6,1024].sort(function(a, b) {
@gindis
gindis / loadScript.html
Last active August 29, 2015 14:27
动态加载js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>动态加载js</title>
</head>
<body>
<script>
(function(){
function loadScript(url, callback) {
@gindis
gindis / gist:10956435
Last active August 29, 2015 13:59
记录上一次浏览页面位置
!function (){
'use strict';
if (localStorage) {
var docEle,
w = window,
d = document,
l = localStorage,
t = location.href,
browserName=navigator.userAgent.toLowerCase();
@gindis
gindis / gist:9085040
Last active August 29, 2015 13:56
ANGULARJS TEST
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>ANGULARJS TEST</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="Ctrl1">
@gindis
gindis / gist:8877840
Last active August 29, 2015 13:56
css 外链 or 内嵌

外链

优点:

  1. 便于复用
  2. 便于管理

缺点:

  1. 额外的http请求
  2. 造成css浪费 (比如a)
  3. 可能造成链接404
@gindis
gindis / font.css
Last active January 4, 2016 15:59
font-family
<style>
//zhihu.com
.fofa-1 {
font-family: 'Open Sans','Helvetica Neue',Arial,"Hiragino Sans GB",sans-serif;
}
//blog
.fofa-2 {
font-family: palatino, "times new roman", serif;
}
//jianshu.io
@gindis
gindis / gist:8643624
Created January 27, 2014 05:22
ng https

跨域访问Api

curl -X OPTIONS -i 'http://api.example.com' -H "Origin: http://example.com"

跨域访问Api

@gindis
gindis / gist:8432630
Created January 15, 2014 08:22
Media Query CSS
/*iPad及以下,所有小于(不等于)960宽度的平板电脑*/

@media only screen and (max-width: 959px)  {}

/*仅iPad竖屏,所有小于(不等于)960宽度的平板电脑的竖屏*/
@media only screen and (min-width: 768px) and (max-width: 959px)  {}

/*iPhone及以下*/
@media only screen and (max-width: 767px) {}