May 2013
4 posts
1 tag
String replace all:
var str="<>";
str=str.replace(/\'/g,"’");//替换半角单引号为全角单引号
str=str.replace(/\"/g,"”");//替换半角双引号为全角双引号
str=str.replace(/</g,"《").replace(/>/g,"》");
1 tag
POST with AnglarJS $http
Default conten-type is:
application/json;charset=UTF-8
Need to change it and the data you sent with it:
How can I make angular.js post data as form data instead of a request payload?
1 tag
AngularJS - Communication Between Controllers &... →
虽然感觉特别搓,但直接按egghead里service方法写,通过input.value的方法改变model值时two way binding竟然不生效,又不会用$watch,最后还是这招解决了。
1 tag
javascript - check all extensions from a multiple... →
April 2013
10 posts
1 tag
How to change the Content of a with Javascript -... →
For all the downvoters and non-believers.
2 tags
那些年,我们看过的各种设计理论法则 →
skeumorphic and flat(Barcelona)
1 tag
.htaccess
.htaccess Tutorial
.htaccess Guide
Remove index.php in the URL for Codeigniter:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /selfcontrol/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Uncomment one of the following rewrite rules.
#Some servers require the ? after index.php, some don't
#RewriteRule...
1 tag
ASCII and Binary
FTP在传送文件时分为ASC和Bin两种格式,只有文字文件(例如 html 文件)使用ASC,其他的通通使用Bin格式(例如图像文件、压缩文件、可执行文件等等)。
当我们使用ftp时,可简单地把文件分为两种基本类型:文本文件和二进制文件;文本文件也称为ASCII文件,其文件内容遵循ASCII的定义,其主要特征是文件内容由若干行组成,可以使用操作系统的显示、编辑命令来显示和编辑ASCII文件的内容,它使用的传输模式是asc;二进制文件(Binary File)是指除ASCII文件以外的所有文件格式,它使用的传输模式是bin;需要注意的是,可以将ASCII文件按二进制模式传输,但决不能将二进制文件按ASCII模式传输,否则二进制文件的内容会遭到破坏而无法使用。
ASCII 切换传输模式为文字模式(只能用来传送文字文件);
BINARY...
1 tag
Elapsed Time: Why Video Discovery Startups All... →
1 tag
世界上有两类软件公司:一类像工厂,而另一类像电影摄制组 →
1 tag
Upload And Preview Image Without Refresh
When we use the iframeSubmit function, we’ll have the form point to upload.php for image submissions and the result will be loaded within the iframe (which is now a hidden element in the page). The upload.php script should process the submission and generate an iframe content which will call the function defined and passed by iframeSubmit, with the results of the operation.
That’s the...
1 tag
地震.css
地震.css
html {
-webkit-filter: grayscale(100%);
-moz-filter: grayscale(100%);
-ms-filter: grayscale(100%);
-o-filter: grayscale(100%);
filter:progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
zoom: 1;
}
1 tag
Smarty Replace Line Breaks
{$var|regex_replace:”/[\r\n]/” : ” “}
1 tag
W3C DOM Compatibility - Core →
removeAttribute() IE6/7 support: almost.
March 2013
1 post
The danger of the trailing dot in the domain name →
February 2013
1 post
1 tag
Object comparison in JavaScript
http://stackoverflow.com/questions/1068834/object-comparison-in-javascript
Why not JSON.stringify it then compare?
JSON.stringify removes properties that are set to undefined.
What if the data is the same but the order of the keys is different?
String performance.
December 2012
1 post
1 tag
screen.height, screen.availHeight,...
屏幕分辨率高度,屏幕内可用高度(桌面去掉任务栏,浏览器可用高度),浏览器内可用高度
$.getWinSize = function() {
if (window.innerWidth != undefined) {
return [window.innerWidth, window.innerHeight];
} else {
var body = document.body, de = document.documentElement;
return [Math.max(de.clientWidth, body.clientWidth), Math.max(de.clientHeight, body.clientHeight)];
}
};
October 2012
5 posts
1 tag
CodeIgniter Rest Server
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
You’ll need another file: /application/libraries/Format.php.
3 tags
Read Request Payload in Codeigniter
I was using Codeigniter with Backbone. When I try to call the save() method in the Backbone it sent a POST Request to the server. But it sends data to the server using a Request Payload and not the standard Form Data approach that jQuery, and standard HTML forms submit with.. After a bit study I think there are two easy way to handle this.
On the front end you can enable Backbone.emulateJSON()...
2 tags
RESTFUL API
http://blog.apigee.com/detail/restful_api_design
1 tag
Algorithm
http://net.tutsplus.com/tutorials/tools-and-tips/understanding-the-principles-of-algorithm-design/
1 tag
CSS clip
http://www.stinkdigital.com/
http://www.zhangxinxu.com/wordpress/?p=1565
September 2012
10 posts
1 tag
.htaccess Rewrite
One .htaccess File
http://www.farinspace.com/codeigniter-htaccess-file/
Regular expressions
^ begins the line to match.
$ ends the line to match. So, ^folder1$ matches folder1 exactly.
. stands for “any non-whitespace character” (example: a, B, 3).
* means that the previous character can be matched zero or more times. So, ^uploads.*$ matches uploads2009, uploads2010, etc.
^.*$...
1 tag
Updating address bar with new URL without hash or...
How can Destopper does this? Here is the answer.
http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page
2 tags
EDM
Gmail下,background:url()里的路径会被自动置空
Gmail下,div的height属性会被替换为min-height
Gmail下,所有position相关属性会被删掉
支持margin
1 tag
Lazy Load Script
You can always use $.getScript, or the old fashioned way:http://friendlybit.com/js/lazy-loading-asyncronous-javascript/
One fun thing about this entry:
There’s been competitions for writing a short and compact version of addEvent, and the winner of that competition was John Resig, with this little beauty:
function addEvent(obj, type, fn) {
if (obj.attachEvent) {
obj['e'+type+fn] = fn;
...
1 tag
bind, live, delegate & this
The events attribute
The Backbone events attribute allows us to attach event listeners to either custom selectors, or directly to el if no selector is provided. An event takes the form {"eventName selector": "callbackFunction"} and a number of DOM event-types are supported, including click, submit, mouseover, dblclick and more.
What isn’t instantly obvious is that under the...
1 tag
1 tag
Tumblr Pin Button Animation Implementation
1 tag
Vim 2 shortcuts
Paste
:reg,查看寄存器
“,进入选择寄存器模式
按对应数字字符键选择寄存器
p
1 tag
vim 1 plugins
pathogen.vim
Easy manipulation of ‘runtimepath’, ‘path’, ‘tags’, etc.
http://www.vim.org/scripts/script.php?script_id=2332
mkdir -p ~/.vim/autoload ~/.vim/bundle
Then install in ~/.vim/autoload, win in …/Vim/vimfiles/autoload.
zencoding
http://www.vim.org/scripts/script.php?script_id=2981
unzip in ~/.vim/bundle/zencoding, win in...
1 tag
ubuntu 6
kill
1
ps -e
sudo kill 0000
2
pgrep evolution
sudo kill 0000
shutdown
好像ubuntu的终端中默认的是当前用户的命令,只是普通用户,因此在终端器中可以使用sudo -sh 转换到管理员root用户下执行命令。
shutdown —help 可以查看shutdown命令如何使用,当然也可以使用man shutdown命令。
shutdown -h now 现在立即关机
shutdown -r now 现在立即重启
shutdown -r +3 三分钟后重启
shutdown -h +3 “The System will shutdown after 3 minutes” 提示使用者将在三分钟后关机
shutdown -r 20:23...
August 2012
3 posts
1 tag
/*@
/*@ 不要写在一起 要这样/*[空格]@,以及//@ 要写成//[空格]@,不然在IE下会脚本报错。
http://www.blueidea.com/tech/web/2006/3238.asp
git
Git Diff with VImdiffu
http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/
1 tag
opera:crossnetworkwarning
内网里用opera上咱们的网站一张图都加载不出来:
Warning
http://hiphotos.baidu.com/baidu/pic/item/***.jpg
A page on the public internet requests data from your private intranet. For security reasons, automatic access is blocked, but you may choose to continue.
Continue
Always continue when data is requested from this server on my private intranet
Generated by Opera.
...
July 2012
9 posts
1 tag
XSS & CSRF
XSS
http://netsecurity.51cto.com/art/200804/69856.htm
<a href="javascript:alert(0)"></a>
<a href="http://www.baidu.com/site?data=forged"></a>
CSRF
http://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html
1 tag
obj.requestAnimFrame - Illegal Invocation
http://stackoverflow.com/questions/9677985/uncaught-typeerror-illegal-invocation-in-chrome
Plus, requestAnimFrame: http://paulirish.com/2011/requestanimationframe-for-smart-animating/
1 tag
JavaScript Object Shallow Copy
在jsbin上跑了个简单例子。
function a(b){
var m = b;
var n = b;
b.a = 1;
console.log(b.a + ' ' + m.a + ' ' + n.c );
n.c = 2;
console.log(b.c + ' ' + m.a + ' ' + n );
}
var x = {};
a(x);
console.log(x);
证明在js里对象(包括数组)怎么赋值或传值,永远都是浅度复制,永远只有一个拷贝,而其他值类型都是深度复制。
2 tags
JavaScript Partial Application
Define
…the process of fixing a number of arguments to a function, producing another function of smaller arity
…the user can specify arguments that will be filled in later by specifying undefined, for it.
Ref
https://github.com/shichuan/javascript-patterns/blob/master/function-patterns/partial-application.html
http://ejohn.org/blog/partial-functions-in-javascript/
2 tags
JavaScript Curry
Define
Used to create new functions dynamically by partially applying a set of arguments.
Currying allows you to easily create custom functions by partially invoking an existing function. Generally, curry returns a copy of the invoking function, with its first n arguments pre-assigned with the arguments passed by the curry invocation.
Filling in the first couple arguments of a function (and...
2 tags
js规范两则
1.
关键词、条件括弧后面使用空格;运算操作符号两侧使用空格;语句分割符‘,’后面使用空格
var name[空格]=[空格]value;
if[空格](a,[空格]b) {
}
2.
单行过长应在适当位置予以换行,增强可读性 if 语句括号中的条件若过多过长,应予以折行;折行后,||、&& 等符号应与 “(” 后的第一个字母纵向对齐
if (condition1
&& condition2
|| condition3) {
}
if、while、for、do语句的执行体总是用”{“和”}”括起来,即使在其结构体内只有一条语句
if (s==100) {
alert('shit!');
}
1 tag
"use strict";
优点:http://www.nczonline.net/blog/2012/03/13/its-time-to-start-using-javascript-strict-mode/
http://dmitrysoshnikov.com/ecmascript/es5-chapter-2-strict-mode/
反正不影响老浏览器..
2 tags
ECMAScript, JScript & JavaScript
JS: http://en.wikipedia.org/wiki/JavaScript#Versions
ES 5( ES 6, non-standard ): http://kangax.github.com/es5-compat-table/
JS版本处在非常混乱的状态,JS其实是一个ES和一些non-standard方法的交集,FX对JS版本的支持最前卫,IE自创JScript,使用的1.5版。
2 tags
The Singleton Pattern
http://addyosmani.com/resources/essentialjsdesignpatterns/book/#singletonpatternjavascript
Singletons differ from static classes (or objects) as we can delay their initialization, generally because they require some information that may not be available during initialization time.
var SingletonTester = (function () {
// options: an object containing configuration options for the singleton
...
June 2012
1 post
1 tag
setInterval
>Because functions scheduled with setInterval are called regardless of whether the browser tab they belong to is showing, using it meant that computers were doing all the work of displaying every open WebGL tab all the time, hidden or not. This was obviously a Bad Thing, and was the reason why requestAnimationFrame was introduced; functions scheduled using it are only called when the tab is...
May 2012
5 posts
1 tag
clearfix
几次面试都被问到清浮动的问题,我就直接把经典的clearfix和bootstrap里看见的.clearfix()的mixin方法报了出来,但其实我写了这么都页面,从来都不知道清浮动到底有什么用,又不好意思说,问了不少人都没给我讲清楚,今天写页面时才终于明白,原来清浮动是用来防止浮动的子元素导致的父元素塌缩的…
一个div.body后有个div.footer,.body里两个div一float,.body高度就成0了,本来遇到这种问题我一向是一个overflow:hidden解决的,但这次里面子div里有个东西需要跃出父div形成样式,这是才发现原来清浮动就可以防止塌缩..
1 tag
user-select →
当然其实只用css就可以实现,如果不兼容老IE。
另外,关于-webkit-user-select和-moz-user-select一个不同点:http://stackoverflow.com/questions/3077950/user-select-none-and-strange-behaviour-in-firefox
Subversion 教程 →
Subversion 官方:http://subversion.apache.org/
1 tag
JS: Hook into existing object methods
NodeJS, Connect, middleware: Log it
function logItHandle(req, res, next) {
var writeHead = res.writeHead; // Store the original function
// Wrap writeHead to hook into the exit path through the layers.
res.writeHead = function (code, headers) {
res.writeHead = writeHead; // Put the original back
// Log the outgoing response
console.log("Response " + counter +...
1 tag
Ubuntu 5
vim
Many of the Vimscript commands you’ll learn can be used in your day-to-day editing as well, but they’re only helpful if they’re in your muscle memory, which simply doesn’t happen from just reading.
看了篇吹NB的教程,看到了个不错的教程,还有KK推荐的learn vimscript the hard way,用apt-get装了vim和vim-gnome,做了下vimtutor
vimrc
...